python - Adding to a dictionary directly from input() -
the following snippet want do:
m = [int(x) x in input().split()] d = {} in range(26): d[chr(i+97)] = m[i]
can done directly while taking input using generator function or like:
((d[chr(i+97)] = k) in range(26) , k in input().split())
edit: found solution; using zip(). this:
d = {(u,v) (u,v) in zip(m,map(int,input().split()))}
this works doesn't ordered , d[chr(97)] seems missing.
d ={chr(i+97):x i, x in enumerate(input().split())}
Comments
Post a Comment