0
목록 목록을 튜플 목록으로 변환하려고합니다.파이썬 목록 목록을 튜플 목록으로 변환합니다.
내 파이썬 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
들과 b
들로 변환하는 방법은 무엇입니까 ?
답변 - 주석 :
하나는 d['bar'] = map(tuple, d['bar'])
을 할 필요가있다.
'D [ '바'] =지도 (튜플, D [ '바'])'아마 당신이 –
계신 내가있다는 - 완벽하게 잘되었다! – baibo