Python学习笔记(4)——Python Lists and Dictionaries
来源:互联网 发布:手机淘宝退货流程图 编辑:程序博客网 时间:2024/05/16 17:30
突然发现我的博客竟然还有阅读量
是不是写的太随意了
哎呀 不管啦 写给自己看:p
5.
suitcase = ["sunglasses", "hat", "passport", "laptop", "suit", "shoes"]# The first and second items (index zero and one)first = suitcase[0:2]# Third and fourth items (index two and three)middle = suitcase[2:4]# The last two items (index four and five)last = suitcase[4:6]
6
animals = "catdogfrog"# The first three characters of animalscat = animals[:3]# The fourth through sixth charactersdog = animals[3:6]# From the seventh character to the endfrog = animals[6:]
7.
animals = ["aardvark", "badger", "duck", "emu", "fennec fox"]duck_index = animals.index('duck') # Use index() to find "duck"# Your code here!animals.insert(duck_index,'cobra')print animals # Observe what prints after the insert operation
9.
start_list = [5, 3, 1, 2, 4]square_list = []# Your code here!for x in start_list: square_list.append(x**2)square_list.sort()print square_list
12.
# key - animal_name : value - location zoo_animals = { 'Unicorn' : 'Cotton Candy House', 'Sloth' : 'Rainforest Exhibit', 'Bengal Tiger' : 'Jungle House', 'Atlantic Puffin' : 'Arctic Exhibit', 'Rockhopper Penguin' : 'Arctic Exhibit'}# A dictionary (or list) declaration may break across multiple lines# Removing the 'Unicorn' entry. (Unicorns are incredibly expensive.)del zoo_animals['Unicorn']# Your code here!del zoo_animals['Sloth']del zoo_animals['Bengal Tiger']zoo_animals['Rockhopper Penguin'] = 'anthing' #23333print zoo_animals
14.
inventory = { 'gold' : 500, 'pouch' : ['flint', 'twine', 'gemstone'], # Assigned a new list to 'pouch' key 'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']}# Adding a key 'burlap bag' and assigning a list to itinventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth']# Sorting the list found under the key 'pouch'inventory['pouch'].sort() # Your code hereinventory['pocket'] = ['seashell','strange berry','lint']inventory['backpack'].sort()inventory['backpack'].remove('dagger')inventory['gold'] += 50
阅读全文
0 0
- Python学习笔记(4)——Python Lists and Dictionaries
- Python学习——Lists and Dictionaries
- Python学习笔记(7)Mouse Input, More Lists and Dictionaries
- Python 入门教程 8 ---- Python Lists and Dictionaries
- Python 的Lists、Tuples、Dictionaries和Sets
- Python dict dictionaries Python 数据结构——字典
- Python dict dictionaries Python 数据结构——字典
- python学习笔记15--Lists
- Python学习笔记(十六)----Python列表(Lists)
- Python[八]:Dictionaries
- Python中Dictionaries浅析
- Beginning Python - Chapter4 : Dictionaries
- learning Python-Dictionaries
- 3.11 - Dictionaries in Python
- Datacamp-python-Dictionaries
- Python For Kids学习笔记03:Strings, Lists, Tuples, and Maps
- Python学习笔记(—):初识python
- Think Python: Chapter 11 Dictionaries
- pat 1070. 结绳
- 跳转回制定控制器
- spark job, stage, task介绍
- STM32堆栈整理
- 如何在Ubuntu中查找自己安装的软件包
- Python学习笔记(4)——Python Lists and Dictionaries
- poj3185 The Water Bowls 开关问题
- Mysql之事务(并发)初体验
- ThinkCmf目录结构
- [leetcode122].为何此时贪心解是最优解 ?
- Numpy.Zeros等
- 宽高自适应
- [hibernate]Turn your Session into FlushMode.COMMIT/AUTO,请教这种配置怎么处理
- 抓包神器Charles使用