【377】only one element in a tuple
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的更多相关文章
- 【原创】leetCodeOj --- Majority Element 解题报告(脍炙人口的找n个元素数组中最少重复n/2次的元素)
题目地址: https://oj.leetcode.com/problems/majority-element/ 题目内容: Given an array of size n, find the ma ...
- 【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 ...
- 【leetcode】Find Peak Element
Find Peak Element A peak element is an element that is greater than its neighbors. Given an input ar ...
- 【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 ...
- 【LeetCode】169 - Majority Element
Given an array of size n, find the majority element. The majority element is the element that appear ...
- 【LeetCode】27 - Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. T ...
- 【leetcode】Find Peak Element ☆
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- 【vue】使用vue+element搭建项目,Tree树形控件使用
1.依赖安装 本例中,使用render-content进行树节点内容的自定义,因此需要支持JSX语法.(见参考资料第3个) 在Git bash中运行一下指令 cnpm install\ babel-p ...
- 【vue】vue使用Element组件时v-for循环里的表单项验证方法
转载至:https://www.jb51.net/article/142750.htm标题描述看起来有些复杂,有vue,Element,又有表单验证,还有v-for循环?是不是有点乱?不过我相信开发中 ...
随机推荐
- Javascript-关于for in和forEach
JS-for in:用来遍历对象 //遍历对象 for in var opts={name:'xiaofei',age:'28岁',job:'web前端工程师'} for (var k in opts ...
- cocos源码分析--用Sprite加载自定义着色器
本文写一个使用动态更新属性变量的自定义着色器.在这个例子中,小图标的位置根据手指的触摸而移动,以屏幕重点为参照物,屏幕中向下的部分根据手指的点击乘以一个绿色的颜色值,向上的部分乘以一个红色的颜色值. ...
- h5登录页面
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- 小数据池 id
1. 小数据池, id() 小数据池针对的是: int, str, bool 在py文件中几乎所有的字符串都会缓存. id() 查看变量的内存地址 # id()函数可以帮我们查看一个变量的内存地址 # ...
- 零基础学习python_字典(25-26课)
今天学到后面的知识,突然发现之前学习到的字典列表啥的都有点忘了,打算补一下之前学到的字典,到时候你看的时候,字符串.列表.字典.元祖这几个没啥顺序,刚开始学的时候了解下方法,当然你可以死记硬背下,后面 ...
- (转)日期类型的input元素设置默认值为当天
原文地址 html5的form元素对日期时间有丰富的支持 <input type="date"> <input type="time"> ...
- h5py库安装问题解决
H5py官网教程完全有问题,这个大家都这么说,但是貌似问题出现在Numpy上,由于numpy的版本过高! 这里是官网的教程:http://docs.h5py.org/en/latest/build.h ...
- [Unity移动端]Touch类
Touch类的信息只能在移动端(触摸屏)上能够获取,在编辑器上是不能获取到的.因此,为了方便测试,可以打包apk后在模拟器上跑: unity打包apk:https://www.jianshu.com/ ...
- 实战ELK(1) 安装ElasticSearch
第一步:环境 linux 系统 Java 1.8.0 elasticsearch-6.5.1 第二步:下载 2.1 JDK:https://mirrors.aliyun.com/centos/7.5 ...
- JVM Tools
Java VisualVm 提供可视化界面展示运行在JVM上应用的信息.这些信息可用于诊断剖析应用. Jconsole Jconsole是基于JMX监视工具.Jconsole使用内置的JMX在java ...