안녕세계

[Python] tuple을 dict로 변환 본문

[Python] tuple을 dict로 변환

Junhong Kim 2019. 1. 19. 15:06
728x90
반응형


[방법1]

t = ((1, 'a'), (2, 'b'))
ret = dict((y, x) for x, y in t)

print(ret)
# {'a': 1, 'b': 2}


[방법2] *recommend

t = ((1, 'a'), (2, 'b'))
ret = dict(map(reversed, t))

print(ret)
# {'a': 1, 'b': 2}

References

https://stackoverflow.com/questions/3783530/python-tuple-to-dict


728x90
반응형
Comments