0

Guys, I am trying to sort a list. But Python does not let me set my new sorted list into a variable. here:

list1 = ['a', 'z', 'b', 'y']
sorted_list = list1.sort()
return sorted_list

When I run this on my interpreter, instead of printing my string sorted, it prints "None"
Why does it do that?

But when I go:

list1 = ['a', 'z', 'b', 'y']
list1.sort()
print list1

it returns my string sorted. But why does it return "None" when I assign it to a variable?

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by ultimatebuster
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.