hello having difficulty getting function work.
i given list (rl) of restaurants in namedtuples , asked create function sorts list alphabetically order , returns name of each namedtuple. have far
def alphabetical_names(r: restaurant) -> list: '''returns name of restaurants sorted alphabetically ''' restaurants in sorted(r): return(restaurant.name) print(alphabetical_names(rl))
however when run thing 'property object @ 0x034a4a80>' , don't know why
there number of problems code.
- you have declared r restaurant not list.
- you give variable name for loop plural - confusing.
- most importantly, have referred restaurant class, not instance of restaurant.
try:
def alphabetical_names(r: list) -> list: '''returns name of restaurants sorted alphabetically ''' restaurant in sorted(r): return(restaurant.name) print(alphabetical_names(rl))
however still has problem, return first result, not list. try:
def alphabetical_names(r: list) -> list: '''returns name of restaurants sorted alphabetically ''' return sorted(r): print(alphabetical_names(rl))
this may not sort entries in order want, possible need provide sorted cmp function change sort order.
Comments
Post a Comment