Recently I am doing the assignment of COMP9021. It is too difficult and it is about the Knight and Knave. While I tried to finish this assignment, however I only finnished the code with the testcase Professor Martin gave. I encontered a problem was that if there is only one element in a tuple, actually we need to add a comma.

Examples as follows can help us to understand it.

a = ((2, 3),)
b = ((2, 3))
c = (2,)
d = (2) print(a, b, c, d)
print(len(a), len(b), len(c)) outputs:
((2, 3),) (2, 3) (2,) 2
1 2 1

Actually, variable a is a tuple with only one element which is (2, 3).

Variable b is a tuple with two elements which is 2 and 3.

So if you want to create a tuple with only one element, you need to add a comma otherwise you will create a different tuple.

【377】only one element in a tuple的更多相关文章

  1. 【原创】leetCodeOj --- Majority Element 解题报告(脍炙人口的找n个元素数组中最少重复n/2次的元素)

    题目地址: https://oj.leetcode.com/problems/majority-element/ 题目内容: Given an array of size n, find the ma ...

  2. 【JAVA】【Eclipse】出现This element neither has attached source nor attached Javadoc...的解决方法

    This element neither has attached source nor attached Javadoc and hence no Javadoc could be found Ec ...

  3. 【leetcode】Find Peak Element

    Find Peak Element A peak element is an element that is greater than its neighbors. Given an input ar ...

  4. 【leetcode】Kth Largest Element in an Array (middle)☆

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  5. 【LeetCode】169 - Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  6. 【LeetCode】27 - Remove Element

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  7. 【leetcode】Find Peak Element ☆

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...

  8. 【vue】使用vue+element搭建项目,Tree树形控件使用

    1.依赖安装 本例中,使用render-content进行树节点内容的自定义,因此需要支持JSX语法.(见参考资料第3个) 在Git bash中运行一下指令 cnpm install\ babel-p ...

  9. 【vue】vue使用Element组件时v-for循环里的表单项验证方法

    转载至:https://www.jb51.net/article/142750.htm标题描述看起来有些复杂,有vue,Element,又有表单验证,还有v-for循环?是不是有点乱?不过我相信开发中 ...

随机推荐

  1. http、TCP/IP协议与socket之间的区别(转载)

    http.TCP/IP协议与socket之间的区别  https://www.cnblogs.com/iOS-mt/p/4264675.html http.TCP/IP协议与socket之间的区别   ...

  2. CGo中传递多维数组给C函数

    转自:http://www.cnblogs.com/cobbliu/p/5035358.html package main /* #include <stdio.h> #include & ...

  3. MySQL查询表的所有列名,用逗号拼接

    问题场景 在MySQL中,需要以逗号拼接一个表的所有字段 sql语句 SELECT GROUP_CONCAT(COLUMN_NAME SEPARATOR ",") FROM inf ...

  4. Android Studio设置自定义字体

    Android Studio设置自定义字体 (1)进入设置页面,File->Settings (2)自定义字体Editor->Colors&Fonts->Font (3)点击 ...

  5. Centos7使用pxe安装KVM虚拟机

    Centos7使用pxe安装KVM虚拟机 一.安装服务所需的软件 [root@localhost ~]yum install nginx dhcp vsftpd syslinux -y [root@l ...

  6. Django之Django debug toolbar调试工具

    一.安装Django debug toolbar调试工具 pip3 install django-debug-toolbar 如果出错命令为 pip install django_debug_tool ...

  7. 2-Zookeeper、HA安装

    1.Zookeeper安装 1.解压 zookeeper 到安装目录中/opt/app/zookeeper 中. 2.在安装目录下创建data和logs两个目录用于存储数据和日志: cd /opt/a ...

  8. PowerDesigner 物理数据模型(PDM) 说明

    ref: https://blog.csdn.net/tianlesoftware/article/details/6874067 一.     PDM 介绍 物理数据模型(Physical Data ...

  9. [python,2018-01-15] 冒泡法排序

    想写一个冒泡法排序,没什么思路,就先写了个java的 public static void main(String[] args) { int array[] = {88,2,43,12,34,8,6 ...

  10. centos出现“FirewallD is not running”

    最近在服务器centos上安装了rdis数据库,默认是不开启远端访问功能,需要设置一下防火墙,在开放默认端口号 8888时提示FirewallD is not running,经过排查发现是防火墙就没 ...