VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > python爬虫 >
  • Python字典 2

动态创建字典,并添加到列表

dictionaries=[]
mark=1
for dic in range(30): dictionary={"first":"Python","second":"VB.net","third":"C#","mark":mark}
    dictionaries.append(dictionary)
    mark+=1
for d in dictionaries
  print(d)


dictionaries=[]

mark=1

for dic in range(30): dictionary={"first":"Python","second":"VB.net","third":"C#","mark":mark}

    dictionaries.append(dictionary)

    mark=mark+1

for d in dictionaries[:3]:

  print(d)

这里的for d in dictionarys[:3]:

一行,用于限制只显示前三行

dictionarys=[]
mark=1
for dic in range(0,9): dictionary={"first":"Python","second":"VB.net","third":"C#","mark":mark}
    dictionarys.append(dictionary)
    mark=mark+1
for d in dictionarys[3:5]:
  print(d)

在字典里嵌套列表

dictionary={"first":"python","second":"VB.net","third":["css","javascript","flash"]}
for dic in dictionary["third"]:
  print(dic)




字典里嵌套列表

 

dictionary={"first":["python","VB.net","C#"],"second":[“ css”,”JavaScript”,”Flash”]}

for key,values in dictionary.items():

    print("\n"+key.title()+"列表值为:")

    for val in values:

      print("\t"+val.title())

字典里嵌套字典

dictionary={"first":{"one":"python","two":"VB.net","three":"C#"},"second":{"one":"css","two":"javascript","three":"flash"}}
for key,values in dictionary.items():
    print("\n"+key.title()+"字典内容为:")
    for k,val in values.items():
        print("\t键为:"+k)
        print("\t值为:"+val+"\n")







相关教程