Apr-22-2017, 02:46 PM
Thak you all! This helped me already quite a lot.
The code looks now like this:
Next step would be to somehow let python accept for groceries an input for groceries, like
The code looks now like this:
locations = {'banana': 1, 'steak': 5, 'water': 9, 'cheese': 4, 'spam': 2, 'pizza': 8} groceries = ['banana', 'steak', 'spam', 'cheese', 'pizza'] groceries.sort(key = lambda x: locations[x]) for item in groceries: print('{} is located in isle: {}'.format(item, locations[item]))
Output:banana is located in isle: 1
spam is located in isle: 2
cheese is located in isle: 4
steak is located in isle: 5
pizza is located in isle: 8
in the output are the items ordered after their values as stated in the dictonairy, that´s perfect.Next step would be to somehow let python accept for groceries an input for groceries, like
locations = {'banana': 1, 'steak': 5, 'water': 9, 'cheese': 4, 'spam': 2, 'pizza': 8} groceries = input ('What would you like to buy? ')then you enter your list and it returns the entered items arranged from isle 1-10.