+ 1
list doubt.
Hello teacher, I tried a code for the below problem statement. (Write a program that accepts a comma-separated sequence of words as input and prints the words in a comma-separated sequence after sorting them alphabetically.) My code is below .But I got None as output. code: words=input("Enten words:") a=words.split(",") b=a.sort() print(b) But again I wrote the code as below. And I got an answer. words=input("Enten words:") a=words.split(",") a.sort() print(a) so could you please tell me what is difference between these codes? And why it does not give me the output in 1st program.
1 Resposta
+ 6
sort in an inplace sort.it returns None.So b is None and a is sorted.
in opposit sorted(a) returns a new list.
a.sort()
print(a)