Python convert pairs list to dictionary -
i have list of 50 strings integer representing how occur in text document. have formatted shown below, , trying create dictionary of information, first word being value , key number beside it.
string = [('limited', 1), ('all', 16), ('concept', 1), ('secondly', 1)]
the code have far:
my_dict = {} pairs in string: int in pairs: my_dict[pairs] = int
like this, python's dict()
function designed converting list
of tuple
s, have:
>>> string = [('limited', 1), ('all', 16), ('concept', 1), ('secondly', 1)] >>> my_dict = dict(string) >>> my_dict {'all': 16, 'secondly': 1, 'concept': 1, 'limited': 1}
Comments
Post a Comment