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. 禅道-bug管理系统部署

    官方下载: https://www.zentao.net/framework/zentao11.2-80109.html 官方使用说明:(含安装及使用说明,很详细) https://www.zenta ...

  2. lightgbm的sklearn接口和原生接口参数详细说明及调参指点

    class lightgbm.LGBMClassifier(boosting_type='gbdt', num_leaves=31, max_depth=-1, learning_rate=0.1, ...

  3. 数据分箱:等频分箱,等距分箱,卡方分箱,计算WOE、IV

    转载:https://zhuanlan.zhihu.com/p/38440477 转载:https://blog.csdn.net/starzhou/article/details/78930490 ...

  4. css一般性

    1. 总差那么几像素!line-height:100%;2. 数据图片,产品图片用img 小图标,logo,修饰网站的图片 用背景3.文字居中 line-height /text-align:cent ...

  5. ubuntu下 net core 安装web模板

    ---恢复内容开始--- 今天想试试在Linux用C#开发WebAPI,查了下,要用: dotnet new -t Web 来建立工程,结果我试了下,出来这段: Invalid input switc ...

  6. Android APP打包错误,Could not resolve com.android.tools.lint:lint-gradle:26.1.2.

    1.Please select the product flavors to build and sign 不专业的翻译一下(请选择产品的味道来制作和签名)什么鬼: 选中Flavors中的选项即可: ...

  7. web框架原理

    web框架的原理: 所有的web应用其实本质上就是socket服务端,而我们的浏览器就是socket客户端. 那么知道了这个之后我们就可以基于socket来写一个我们的服务端: import sock ...

  8. jQuery操作DOM节点的方法总结

    1.parent():获得当前匹配元素集合中每个元素的父元素,该方法只会向上一级对 DOM 树进行遍历 $('li.item-a').parent().css('background-color', ...

  9. 动手动脑-java重载

    有以下例子: 例: Using overloaded methods public class MethodOverload { public static void main(String[] ar ...

  10. 前端笔记二:DOM事件

    ---恢复内容开始--- ---恢复内容结束---