0
我试图将列表列表转换为元组列表。Python将列表列表转换为元组列表
我的Python 2.6.8的代码是:
1. dicts = List of dictionaries all with same set of keys foo and bar
2. for d in dicts:
3. for f in d['foo']: # d['foo'] is a list of lists
4. f.change_some_stuff_inplace(with_some_other_stuff)
5. f = tuple(f) # this obviously doesn't work - it just converts f locally
6. for b in d['bar']: # d['bar'] is also a list of lists
7. b.change_some_stuff_inplace(with_yet_some_other_stuff)
8. b = tuple(b) # again this doesn't work
线条5
和8
不投我的名单到元组,是有办法的f
S和b
秒值进行转换,以就地元组?
ANSWER - 在注释:
需要做的d['bar'] = map(tuple, d['bar'])
。
'd [ '酒吧'] =地图(元组,d [ '酒吧'])'可能是你 –
后在做什么,我 - 它的工作完美! – baibo