hi guys,
when i use .sort() function it shows error any idea,

Do you see anything wrong with your indentation?

And it is preferred if you copy and paste your code here instead of providing a screenshot.

On line 10 you are using a variable out of context. It may be the last value of the loop, but what use is it? Also, it is a tuple, and tuples cannot be sorted, hence the lack of that attribute.

What is it you wish to print?

toppings = [“pepperoni”, “pineapple”, “cheese”, “sausage”, “olives”, “anchies”, “mushrooms”]

prices = [2, 6, 1, 3, 2, 7, 2]

num_two_dollar_slices = prices.count(2)


num_pizzas = len(toppings)

print (“We sell " + str(num_pizzas) + " different kinds of pizza!”)

for pizza_and_prices in zip(toppings, prices):



cheapest_pizza = pizza_and_prices[0]

priciest_pizza = pizza_and_prices[-1]



three_cheapest = pizza_and_prices[:3]

i am doing len’s slice project of python didnt get it since i cant see the solution

Something tells me you want an object named, pizza_and_prices.

pizza_and_prices = zip(toppings, prices)

Now you have an iterator composed of tuples (in the form of key/value pairs). This can be sorted once cast to a list. (A zip object cannot be sorted).

thankyou i guess i get it

1 Like

want to sort price assinding


Recall that we mentioned a zip object cannot be sorted. Cast it to a list, and then use its sort attribute.


Did you wish to sort by price?

i am new and dont understand preety much of coading language so its hard for me to do what you saying

This could mean you are a bit further down the queue than you should be. Have you been following the Learn Python 3 track, with review and extra practice along the way?

yes i did , i cant remember i left anything

Have you practiced the unit on lists and list methods, and the unit that describes what a tuple is, and the unit on iterators, and the unit that introduces lambda?

fact is i was doing data scientist course i remember lists but nor others , in python 3 which also i was inrolled, i just left to do projects, may be thats why i left to have enough practice , i think i should start again only python 3

1 Like

You will be wise to go that route and resume your path later, equipped with a much more capable/enabled toolkit. ‘Learn Python 3’ is the track name. It should be visible in your dashboard.

1 Like

yes that is thankyou i am still career path choosing phase after all these days okey bye goodnight

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.