3个回答
展开全部
>>> 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
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
for each in d:
for v in d[each]:
print each, v
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询