python 中List 与dictionary
来源:互联网 发布:机锋刹那版主淘宝店 编辑:程序博客网 时间:2024/04/28 11:37
1 List 中的平行赋值, 注意其中的last_name前面有一个*,表示如果 List中元素个数大于待赋值的对象个数的话,表示这个对象是一个子list
def test_parallel_assignments_with_extra_values(self):
title, first_names, *last_name = ["Sir", "Ricky", "Bobby", "Worthington"]
self.assertEqual("Sir", title)
self.assertEqual("Ricky", first_names)
self.assertEqual(["Bobby","Worthington"], last_name)
2 这里平行赋值,交换变量,这个牛,不需要第三个变量
def test_swapping_with_parallel_assignment(self):
first_name = "Roy"
last_name = "Rob"
first_name, last_name = last_name, first_name
self.assertEqual("Rob", first_name)
self.assertEqual("Roy", last_name)
3 dictionary表示方法是{},生成dictionary项数据
def test_making_a_dictionary_from_a_sequence_of_keys(self):
cards = {}.fromkeys(('red warrior', 'green elf', 'blue valkyrie', 'yellow dwarf', 'confused looking zebra'), 42)
self.assertEqual(5, len(cards))
self.assertEqual(42, cards['green elf'])
self.assertEqual(42, cards['yellow dwarf'])
- python 中List 与dictionary
- Python 中list, dictionary 与 file相互操作
- Python Dictionary and List
- python dictionary list
- python下 list/dictionary
- python中Dictionary、list、tuple的区别和联系
- Python 取含dictionary的List中某一字段
- Python Container Dictionary And List
- Python List Comprehension, Dictionary Comprehension
- PyCharm中Dictionary与Python package的区别
- 第三章Python解析list,dictionary,set
- Python中的List,Tuple和Dictionary
- 【Python基础】之set, list, dictionary
- python内置类型(list,dictionary, tuple , string, )
- Python基础教程(六):list、tuple、dictionary
- python基础[list,tuple,dictionary,set]
- python中的list,tuple 和 dictionary
- arraylist与list dictionary与hashtable 区别
- (阶段三 dijkstra算法温习1.5)HDU 2680 Choose the best route(使用dijkstra算法求解多源起点的最短路径问题)
- 可执行文件的包含信息
- LeetCode Remove Duplicates from Sorted Array 移除有序数列的重复元素
- C语言打印统计单词长度的直方图<The C Programming Language>课后习题
- FZU 2135 && FOJ11月赛E题
- python 中List 与dictionary
- HTML文本框 圆角显示 样式设置方法
- C++ primer读书笔记——5.12 类型转换
- 网页视频插件
- __asm__ __volatile__ GCC的内嵌汇编语法 AT&T汇编语言语法(一)
- JavaScript学习篇之——DOM学习
- Matlab基本函数-feather函数
- FZU 2138 && FOJ11月赛G题 容斥
- tar打包绝对路径文件