展开全部
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 | >>> mapper { 1 : [ 'a' , 'b' , 'c' ], 2 : [ 'd' ], 3 : [ 'e' ], 4 : [ 'f' , 'g' ], 5 : [ 'h' ], 6 : [ 'i' ], 7 : [ 'a' , 'g' ]} >>> def itertransfer(mapper): ... for k, values in mapper.items(): ... for v in values: ... yield (k, v) ... >>> for k, v in itertransfer(mapper): ... print k, v ... 1 a 1 b 1 c 2 d 3 e 4 f 4 g 5 h 6 i 7 a 7 g >>> >>> result = [] >>> for k, v in mapper.items(): ... result.extend( zip ([k,] * len (v), v)) ... >>> result [( 1 , 'a' ), ( 1 , 'b' ), ( 1 , 'c' ), ( 2 , 'd' ), ( 3 , 'e' ), ( 4 , 'f' ), ( 4 , 'g' ), ( 5 , 'h' ), ( 6 , 'i' ), ( 7 , 'a' ), ( 7 , 'g' )] >>> |
展开全部
dic = {"1":"a,b,c", "2":"d"}
for k, v in dic.items():
valus = v.split(",")
for value in values:
print k, value
for k, v in dic.items():
valus = v.split(",")
for value in values:
print k, value
本回答被网友采纳
展开全部
1 2 3 | for each in d: for v in d[each]: print each, v |
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询