1006- Python 字典(Dictionary) items()方法
来源:互联网 发布:淘宝直播达人合作 编辑:程序博客网 时间:2024/06/09 01:47
Python 字典的一些操作
目录
用 [TOC]
来生成目录:
- Python 字典的一些操作
- 目录
- 字典基础
- Markdown及扩展
- 代码块
字典基础
http://www.runoob.com/python/python-dictionary.html
Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。
d = {key1 : value1, key2 : value2 }
dict = {‘Alice’: ‘2341’, ‘Beth’: ‘9102’, ‘Cecil’: ‘3258’}
Markdown及扩展
代码块
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
Instructions 01.Add a key to inventory called 'pocket' 02.Set the value of 'pocket' to be a list consisting of the strings 'seashell', 'strange berry', and 'lint' 03..sort() the items in the list stored under the 'backpack' key 04.Then .remove('dagger') from the list of items stored under the 'backpack' key 05.Add 50 to the number stored under the 'gold' key
#A Day at the Supermarketshopping_list = ["banana", "orange", "apple"]stock = { "banana": 6, "apple": 0, "orange": 32, "pear": 15}prices = { "banana": 4, "apple": 2, "orange": 1.5, "pear": 3}# Write your code below!def compute_bill(food): total=0 for item in food: total =total + prices[item] # not food[item] return total
0 0
- 1006- Python 字典(Dictionary) items()方法
- Python 字典(Dictionary) items()方法
- 1006- Python 字典(Dictionary)
- Python 字典(Dictionary) setdefault()方法
- Python 字典(Dictionary) has_key()方法
- Python 字典(Dictionary) get()方法
- Python 字典(Dictionary) get()方法
- Python 字典(Dictionary) get()方法
- Python 字典(Dictionary) get()方法
- Python 字典(Dictionary) setdefault()方法
- Python dictionary items() Method
- Python中字典的items()方法
- Python中的字典方法:items(),get(),keys()
- python 字典 get(),items(),iteritems()方法
- 字典的items方法
- Python dictionary 字典
- python Dictionary字典使用
- Python字典 (dictionary)
- ansible通过设置密码的私钥连接实现免密码登录
- spring配置文件详解
- Reverse Words in a String
- CentOS系统下使用 yum 安装 php-mysql 扩展时报错
- 安卓图片三级缓存的集装类
- 1006- Python 字典(Dictionary) items()方法
- Android文字与按钮的GrayText_Button公共类
- HDU 4607 Park Visit
- HDU 1032 The 3n + 1 problem
- Android Webview实现文件下载功能
- 11.9考试总结
- Android 优化布局层次结构
- 通过lspci如何找到驱动?
- opencv C++ Mat类的基本知识(混