Python: dictionary comparisons in splitting lists by first character -
here exercise stumping me:
implement function partition()
splits list of soccer players 2 groups. more precisely, takes list of first names (strings) input , prints names of soccer players first name starts letter between , including , m.
>>>partition([''eleanor'', ''evelyn'', ''sammy'', ''owen'', ''gavin'']) eleanor evelyn gavin >>>partition([''xena'', ''sammy'', ''gavin'']) >>>
here attempt:
def partition(): names=[''eleanor'', ''evenlyn'', ''sammy'', ''owen'', ''gavin''] name in names: if name[0]==''abcdefghijklm'': print (name)
i know i'm going wrong in defining letters, i'm hitting blank, because professor suggested use dictionary comparisons. there way use comparisons split names?
thanks!
name[0] in 'abcdefghijklm'
will tell if character appears in string.
name[0] == 'abcdefghijklm'
compares single letter whole string.
Comments
Post a Comment