n1=['a','b','c']
n2=[1,2,3]
n3=sorted(n1)+sorted(n2)
n4=sorted(n1).extend(sorted(n2))
The problem is n3
is working fine but n4
is not. Why can't extend be after sorted()
?
n1=['a','b','c']
n2=[1,2,3]
n3=sorted(n1)+sorted(n2)
n4=sorted(n1).extend(sorted(n2))
The problem is n3
is working fine but n4
is not. Why can't extend be after sorted()
?
Though sorted()
returns a sorted list, the problem is that extend()
mutates the list and returns None
, so you can achieve what you want by:
n4 = sorted(n1)
n4.extend(sorted(n2))
You aren't using extend correctly the command
n1.extend (n2)
returns a list called n1 which is ['a' , 'b' , 'c' , 1 , 2 , 3 ].
This is because you are extending a list.