python遍历 truple list dictionary的几种方法总结

实例如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

def TestDic1():

dict2 ={'aa':222,11:222}

for val in dict2:

print val

def TestDic2():

dict2 ={'aa':222,11:222}

for (key,val) in dict2.items():

print key,":",val

def TestList1():

list=[1,2,3,4,5,3,2,'ada','fs3']

for i in range(len(list)):

print list[i]

def TestDic3():

dict2 ={'aa':222,11:222}

print "###########iteritems#################"

for k,v in dict2.iteritems():

print "dict[%s]=" % k,v

def TestDic4():

dict2 ={'aa':222,11:222}

print "###########iterkeys,itervalues#######"

for k,v in zip(dict2.iterkeys(),dict2.itervalues()):

print "dict[%s]=" % k,v

def TestList2():

list=[1,2,3,4,5,3,2,'ada','fs3']

for i in list:

print i

以上这篇python遍历 truple list dictionary的几种方法总结就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

本文链接:https://my.lmcjl.com/post/14867.html

展开阅读全文

4 评论

留下您的评论.