python - Sort ages into certain age groups using function? -


i need program read .txt file, example:

mary 15 george 35 harry 18 suu 18 stacy 6 john 56 

and after reading file, program sort ages age groups, are:

[0-6], [7-15], [16-18], [19-30], [31-50], [51-)

i know how make python read file. i'm not sure how sort people age groups shown above.

could me or suggest something?

not asking write me program. need starters.

first create bunch of age groups

groups = {(0,6):[],(7,15):[],(16,18):[],(19,30):[],(31,50):[],(51,5100):[]] 

then iterate on putting each person in group

for person in people:     (min_age,max_age),my_people in groups.iteritems():         if min_age <= person.age <= max_age:            my_people.append(person) 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -