['monaco:1\n', 'russia:2\n', 'denmark:3\n']
into a dictionary in Python 3.3.3, plus any ideas on how to remove the '\n'?
Thanks!
['monaco:1\n', 'russia:2\n', 'denmark:3\n']
into a dictionary in Python 3.3.3, plus any ideas on how to remove the '\n'?
Thanks!
>>> mylist = ['monaco:1\n', 'russia:2\n', 'denmark:3\n']
>>> dict(s.strip().split(':') for s in mylist)
{'denmark': '3', 'russia': '2', 'monaco': '1'}
s.strip().split(':') takes a string and outputs a list of before and after the colon, with whitespace removed from the ends
map. but no worries, thanks for the explanation