python - Reading file and making into dictionary with the values as a list of integers -


i have file in format shown below.

    83 140 228 286 426 612 486 577 836 0 0     aaliyah 0 0 0 0 0 0 0 0 0 380 215     aaron 193 208 218 274 279 232 132 36 32 31 41     abagail 0 0 0 0 0 0 0 0 0 0 958     abbey 0 0 0 0 0 0 0 0 537 451 428     abbie 431 552 742 924 0 0 0 0 752 644 601     abbigail 0 0 0 0 0 0 0 0 0 953 562     abby 0 0 0 0 0 906 782 548 233 211 209     abdiel 0 0 0 0 0 0 0 0 0 925 721     abdul 0 0 0 0 0 0 0 903 0 0 0     abdullah 0 0 0 0 0 0 0 0 0 1000 863     abe 248 328 532 764 733 0 0 0 0 0 0     abel 664 613 626 575 542 491 497 422 381 385 354     abigail 0 0 0 0 854 654 615 317 150 50 14     abigale 0 0 0 0 0 0 0 0 0 0 959 

how able make dictionary name key , list of integers following each name values?

pretty straightfoward:

d = {} open('file.txt') f:     line in f:         parts = line.split()         d[parts[0]] = map(int, parts[1:]) 

the result dictionary d, keyed on first token of each line, list of integers dictionary values.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

ios - Possible to get UIButton sizeThatFits to work? -