遍历字典

作者: 庵下桃花仙 | 来源:发表于2018-10-31 22:29 被阅读5次
# 6-5
rivers_countrys = {'nile': 'egypt', 'yellow river': 'china', 'the ganges river': 'india'}

for river, country in rivers_countrys.items():
    print(river.title() + " flows through " + country.title())

for river in rivers_countrys.keys():
    print(river.title())

for country in rivers_countrys.values():
    print(country.title())

# 6-6
favorite_languages = {
    'lilongbin': 'java',
    'zhaohaibing': 'c',
    'jian': 'python',
}
peoples = ['lilongbin', 'zhaohaibing', 'jian', 'taohuaxian', 'zhudi']

for people in peoples:
    if people in favorite_languages.keys():
        print("Hi " + people.title() + ".Thank you for participating in the survey!")
    else:
        print("Hi " + people.title() + ".Can you accept our investigation?")
Nile flows through Egypt
Yellow River flows through China
The Ganges River flows through India
Nile
Yellow River
The Ganges River
Egypt
China
India
Hi Lilongbin.Thank you for participating in the survey!
Hi Zhaohaibing.Thank you for participating in the survey!
Hi Jian.Thank you for participating in the survey!
Hi Taohuaxian.Can you accept our investigation?
Hi Zhudi.Can you accept our investigation?

相关文章

  • Python - 字典

    空字典 字典遍历 遍历所有键 遍历所有值 遍历所有键值对

  • 07-字典与集合的操作

    字典 创建多个元素的字典 字典的遍历 遍历键 遍历键和值 字典的内置函数 clear() 清空字典 **copy...

  • Python3:列表、字典、元组

    列表的深复制与浅复制 字典的遍历 遍历键 遍历值 遍历键值对 按顺序遍历字典中的键、值 字典与列表相互嵌套 字典列...

  • swift--字典

    创建字典 字典的基本操作 遍历字典 字典合并

  • Python: 遍历字典

    遍历字典 遍历keys 遍历values 遍历keys和values

  • 字典

    本节大纲 字典的定义与特性 字典的常用操作 字典的遍历 字典的定义与特性 字典的常用操作 字典的遍历-案例 扩展-...

  • 跟着大大学python(17)

    6.3 遍历字典 可以遍历字典的所有键-值对、键或值。 6.3.1 遍历所有的键-值对 用于编历字典的for循环,...

  • Dictionary

    字典 遍历

  • Python中的列表和字典遍历

    列表、字典的遍历有很多技巧,如何写出简洁优雅的代码,可能需要了解如下知识: 列表遍历 字典遍历 列表迭代器 字典迭...

  • 遍历数组和字典

    快速遍历方法 遍历数组 For-in 遍历字典 enumerateKeysAndObjectsUsingBlo...

网友评论

    本文标题:遍历字典

    本文链接:https://www.haomeiwen.com/subject/zjiztqtx.html