one interesting concept trying calculating mode (the number appears each line). when there numerous modes, print out lowest numbered mode value. found question calculating mode , trying apply numerous answers, answers apply give me value of 1 (i show you).
as can see, tried several different approaches calculate mode line line.
any suggestions why mode one? thanks.
update: hand-feed code user below suggested output follows:
item 1 item 2 item 3 item 2 item 3 item 2 maxitem 1 maxitem 2 mode of list: 2 none item 1 item 2 item 3 item 2 item 3 item 2 maxitem 1 maxitem 2 mode of list: 2 none item 1 item 2 item 3 item 2 item 3 item 2 maxitem 1 maxitem 2 mode of list: 2 none item 1 item 2 item 3 item 2 item 3 item 2 maxitem 1 maxitem 2 mode of list: 2 none item 1 item 2 item 3 item 2 item 3 item 2 maxitem 1 maxitem 2 mode of list: 2 none item 1 item 2 item 3 item 2 item 3 item 2 maxitem 1 maxitem 2 mode of list: 2 none item 1 item 2 item 3 item 2 item 3 item 2 maxitem 1 maxitem 2 mode of list: 2 none
since mode of list 2, believe mode function working properly. updated code , output original names_list because realized code , output did not match (sorry that). understanding way in have names_list set incorrect calculate mode. not understand how , appreciate suggestions.
update2:
i took advice of user below add names_list = line.split(' ')
code in order correctly parse integers. advice got me correct values, print out smallest integers when there more 1 mode, , still print mode when there one.
i don't see names_list set, think you're omitting code. regardless, based on output not splitting line of file separate numbers.
that is, list [ "a string" ] instead of being [ 1,2,3,4,5,6,5,6 ] bunch of numbers.
the mode computation looks good. try writing test case, this:
print_mode([1,2,3,2,3,2])
feeding list in hand separate parsing errors logic errors.
Comments
Post a Comment