python 怎么提取嵌套在字典里的元组

挑葱 发布于 2016/05/26 21:33
阅读 1K+
收藏 0
index={'合作':[(0, 5)], '每次':[(20, 99), (30, 11), (31, 69), (31, 80)],'在意':[(6, 40), (9, 5)]}

怎么提取对应key的(i,j)信息?



加载中
2
fromdtor
fromdtor
Last login: Thu May 26 23:41:30 on ttys000
➜  ~ python
Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> index = {'合作':[(0, 5)], '每次':[(20, 99), (30, 11), (31, 69), (31, 80)],'在意':[(6, 40), (9, 5)]}
>>> for k, v in index.items():
...  print k
...  for first, second in v:
...   print '\t', first, second
...
在意
	6 40
	9 5
每次
	20 99
	30 11
	31 69
	31 80
合作
	0 5
>>>



挑葱
挑葱
谢谢!
2
fromdtor
fromdtor
>>> for k, v in index['每次']:
...  print k, v
...
20 99
30 11
31 69
31 80
>>>



2
fromdtor
fromdtor
>>> for item in index['每次']:
...  print item[0], item[1]
...
20 99
30 11
31 69
31 80
>>>
>>> for item in index['每次']:
...  f, s = item
...  print f, s
...
20 99
30 11
31 69
31 80
>>>



返回顶部
顶部