Sequences of sequences
I have focused on lists of tuples, but almost all the examples in this chapter also work with lists of lists, tuples of tuples, and tuples of lists. To avoid enumerating the possible combinations, it is sometimes easier to talk about sequences of sequences. In many contexts, the different kinds of sequences (strings, lists and tuples) can be used interchangeably. So how and why do you choose one over the others.
To start with the obvious, strings are more limited than other sequences because the elements have to be characters. They are also immutable. If you need the ability to change the characters in a string (as opposed to creating a new string), you might want to use a list of characters instead.
Lists are more common than tuples, mostly because they are mutable. But there are a few cases where you might prefer tuples:
- In some contexts, like a return statement, it is syntactically simpler to create a tuple than a list.
- If you want to use a sequence as a dictionary key, you have to use an immutable type like a tuple or string.
- If you passing a sequence as an argument to a function, using tuples reduces the potential for unexpected behavior due to aliasing.
Because tuples are immutable, they don’t provide methods like sort and reverse, which modify existing lists. But Python provides the built-in functions sorted and reversed, which take any sequence as a parameter and return a new list with the same elements in a different order.

from Thinking in Python
Sequences of sequences的更多相关文章
- 2. An Array of Sequences
		1. Overview of Built-In Sequences Container sequences: list, tuple, and collections.deque can hold i ... 
- [LeetCode] Repeated DNA Sequences 求重复的DNA序列
		All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ... 
- [Leetcode] Repeated DNA Sequences
		All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ... 
- 论文阅读(Weilin Huang——【AAAI2016】Reading Scene Text in Deep Convolutional Sequences)
		Weilin Huang--[AAAI2016]Reading Scene Text in Deep Convolutional Sequences 目录 作者和相关链接 方法概括 创新点和贡献 方法 ... 
- leetcode   187. Repeated DNA Sequences  求重复的DNA串  ----------  java
		All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ... 
- [UCSD白板题] Longest Common Subsequence of Three Sequences
		Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ... 
- Python数据类型之“序列概述与基本序列类型(Basic Sequences)”
		序列是指有序的队列,重点在"有序". 一.Python中序列的分类 Python中的序列主要以下几种类型: 3种基本序列类型(Basic Sequence Types):list. ... 
- Extract Fasta Sequences Sub Sets by position
		cut -d " " -f 1 sequences.fa | tr -s "\n" "\t"| sed -s 's/>/\n/g' & ... 
- 【BZOJ-4059】Non-boring sequences      线段树 + 扫描线  (正解暴力)
		4059: [Cerc2012]Non-boring sequences Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 440 Solved: 16 ... 
随机推荐
- string 简单实现
			namespace ss{ class string { friend ostream& operator <<(ostream&, const string&); ... 
- error[No partition metadata for topic test-1 due to kafka.common.LeaderNotAvailableException]
			http://stackoverflow.com/questions/23228222/running-into-leadernotavailableexception-when-using-kafk ... 
- bzoj4554: [Tjoi2016&Heoi2016]游戏(二分图匹配)
			4554: [Tjoi2016&Heoi2016]游戏 题目:传送门 题解: 一道很牛逼的匈牙利..和之前模拟赛的一道题有点相似(不过这题不用完美匹配) 我们可以把连续的行和列全部编号(如果之 ... 
- POJ 2184 DP
			思路: f[j]表示当ts的和为j的时候tf的最大值. 这时候要分情况讨论: (我把状态平移了101000) 若ts[i]>=0倒序循环 否则正序 (防止ts被用了多次) f[101000]=0 ... 
- Kettle学习系列之kettle的下载、安装和初步使用(windows平台下)(图文详解)
			不多说,直接上干货! kettle的下载 Kettle可以在http://kettle.pentaho.org/网站下载 http://sourceforge.n ... 
- spring 发送邮件代码示例(带附件和不带附件的)
			import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; import org.springframe ... 
- 模仿百度首页“元宵节汤圆”动图(js的定时任务:setInterval)
			模仿百度首页“元宵节汤圆”动图:(js的定时任务:setInterval) 原理:需要一张切图,通过不断定位使得图片就像一帧一帧的图片在播放从而形成了动画 效果图: 切图地址: https://ss1 ... 
- jquery简介 each遍历 prop attr
			一.JQ简介 jQuery是一个快速.简洁的JavaScript框架,它封装了JavaScript常用的功能代码,提供一种简便的JavaScript设计模式,优化HTML文档操作.事件处理.动画设计和 ... 
- RelativeLayout.addRule()方法
			RelativeLayout.addRule()方法 通过LayoutParams的 addRule方法来额外的添加别的规则了,android.widget.RelativeLayout.Layout ... 
- LVM的创建与挂载
			LVM的诞生: 由于传统的磁盘管理不能对磁盘进行磁盘管理,比如我把/dev/sdb1挂载到了/liu目录下,但是因为数据量过大的原因,此文件系统磁盘利用率已经高达98%,那么我可以直接对这个磁盘进行扩 ... 
