参考链接: Python字典dictionary| items()方法

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 it

inventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth']

# Sorting the list found under the key 'pouch'

inventory['pouch'].sort()

# Your code here

inventory['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 Supermarket

shopping_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

[转载] 1006- Python 字典(Dictionary) items()方法相关推荐

  1. Python 字典(Dictionary. items()方法

    以列表返回可遍历的(键, 值) 元组数组 语法:dict.items() 返回值:返回可遍历的(键, 值) 元组数组 dict = {'Google': 'www.google.com', 'Runo ...

  2. Python 字典(Dictionary) get()方法

    Python 字典(Dictionary) get()方法 描述 Python 字典(Dictionary) get() 函数返回指定键的值,如果值不在字典中返回默认值. 语法 get()方法语法: ...

  3. python字典的items()方法

    python新手学字典的时候只知道字典的增删查改,殊不知还有一个items()方法呢~~~~来看看他是怎么回事吧! 首先对他的描述是:python字典items()函数以列表返回可遍历的(键值)元组数 ...

  4. Python 字典(Dictionary) setdefault()方法

    描述 Python 字典 setdefault() 函数和 get()方法 类似, 如果键不存在于字典中,将会添加键并将值设为默认值. 语法 setdefault() 方法语法: dict.setde ...

  5. 【Python】字典(Dictionary) items()方法

    猜你喜欢:

  6. Python 字典(Dictionary) copy()方法

    https://www.runoob.com/python/att-dictionary-copy.html

  7. python 复制dict_超全的Python 字典(Dictionary)介绍

    字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值 key=>value 对用冒号 : 分割,每个键值对之间用逗号 , 分割,整个字典包括在花括号 {} 中 ,格式如下所示: 键一 ...

  8. dictionary new一个实例_超全的Python 字典(Dictionary)介绍

    字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值 key=>value 对用冒号 : 分割,每个键值对之间用逗号 , 分割,整个字典包括在花括号 {} 中 ,格式如下所示: 键一 ...

  9. [转载] python cmp函数比较字典_Python 字典(Dictionary) cmp()方法

    参考链接: Python cmp方法 Python 字典(Dictionary) cmp()方法 描述 Python 字典(Dictionary) cmp() 函数比较两个字典元素. 语法 cmp() ...

最新文章

  1. 查看Linux硬件信息命令的使用
  2. 在用 Eclipse 搭建 SAP Commerce Cloud 调试环境时,错误和正确的 buildfile
  3. 【开源项目】特斯拉+树莓派实现车牌识别检测系统
  4. 殷浩详解DDD:领域层设计规范
  5. wordpress html页面缓存 cdn,WordPress 下老旧又高效的本地缓存插件 cos-html-cache
  6. [LUOGU]P1451 求细胞数量
  7. 【转】系统管理员之企业生存守则
  8. VC++ 2005 使用BOOST库和WinPcap库
  9. Mybatis-plus实现动态表名查询
  10. 详解 URLLC 前世今生,你 Get 了吗?
  11. iOS开发--xcode快捷键
  12. 上传本地代码到github
  13. 【NOIP2001】【Luogu1029】最大公约数和最小公倍数问题(GCD,枚举)
  14. z变换解差分方程例题_中级数学4 - 多元线性方程
  15. Python脚本编译为可跨平台、跨架构执行的字节码文件pyc方法
  16. 2021年上半年软考真题网络工程师真题及答案解析
  17. 未能加载虚拟光盘VBoxGuestAdditions.iso
  18. plecs / plexim 学习随笔
  19. Spring Cloud Gray 微服务灰度中间件
  20. python3分解质因数_python3 分解质因数

热门文章

  1. 2020 年百度之星·程序设计大赛 - 初赛一 GPA DFS深搜
  2. Kindle一些使用
  3. 【NOIP2001】【Luogu1027】Car的旅行路线
  4. 【bzoj2151】种树
  5. httpservletresponse 重定向浏览器不变的原因_JavaWeb——Servlet——请求转发与响应重定向...
  6. Spring→事务、隔离级别、事务传播行为、编程式事务控制、XML配置声明式事务(原始方式)、XML配置声明式事务(基于tx/aop)、@注解配置声明式事务、优势总结
  7. kali64位下载怎么是AMD_电脑达人速更 NVIDIA 显卡和 AMD 显卡驱动程序又双叒叕更新啦!...
  8. Unity3D基础37:Input控制面板
  9. torch.randn
  10. python 一个简单的天气预报程序