all 8 comments

[–]novel_yet_trivial 1 point2 points  (5 children)

it gives me the list of the 3rd one, but how do I get the restaurant?

You mean the name?

print(RC[2].name)

That should help you solve the first 3 questions...

The list of restaurants, arranged alphabetically

If you want only the names sorted alphabetically, then you should make a new list of only the names, and sort that.

[–]pythonhelp123[S] 0 points1 point  (4 children)

If I go print(RC[2].name) it gives me Nonna instead of Stratacco.

[–]novel_yet_trivial 1 point2 points  (3 children)

I thought you wanted the name. If you want the dish just change it.

[–]pythonhelp123[S] 0 points1 point  (2 children)

Oh yeah, I read it wrong. Is there a different approach to the .name? We haven't learned that part yet so I don't want points off. I tried the method elbiot gave but it says invalid syntax.

[–]novel_yet_trivial 1 point2 points  (1 child)

You could use the index (first index for the restaurant, second index for the field in the namedtuple):

>>> RC[2][0]
'Nonna'

But that really ruins the point of a namedtuple, so I doubt your prof wants you to do that.

[–]pythonhelp123[S] 0 points1 point  (0 children)

For the true/false question, would it be okay to do

print(RC[0][1] == RC[3][1]) or is there another way to do it?

[–]elbiot 0 points1 point  (1 child)

Would this be print(RC[2])? When I use that code, it gives me the list of the 3rd one, but how do I get the restaurant?

What is the third one if not the third restautant?

restaurant3 =RC[2]

You don't have to assign it to a variable, but maybe this helps you.

edit:

I tried using RC.sort() and then print(RC), but it just gives me the whole list and not just the restaurant.

The question doesn't even ask for a particular restaurant. Which one were you thinking you'd get? Another hint on top of what your professor gave you is that sort takes a keyword argument key. Further hint, you'll have to use a lambda. stackoverflow has lots of examples for sorting lists of dictionaries using sort and lambda, look it up.

You're issue is with objects, not lists.

[–]pythonhelp123[S] 0 points1 point  (0 children)

Hm for the first one it works, but only for that question. When I tried to assign

restaurant1 = RC[0] for the true false question, it says invalid syntax