+ 1

Please Explain why a is not equal to b

https://code.sololearn.com/ca1KKjavIhz2/?ref=app

18th May 2020, 9:34 AM
Teja Swaroop
Teja Swaroop - avatar
8 odpowiedzi
+ 5
Because l.sort() function does not return any value, instead it just sort the list "l" . And comparing "none" with a sorted list "b" will return false. Here👇 see this code for better understanding https://code.sololearn.com/cbaHIljTN34K/?ref=app
18th May 2020, 9:48 AM
Arsenic
Arsenic - avatar
+ 5
Because as Arsenic said, .sort() does not return any value. It just sorts the list. sorted on the other hand, returns a new list
18th May 2020, 9:51 AM
Slick
Slick - avatar
+ 4
sorted returns a new list sort modifies the list you are sorting Throw some print statements in there and you'll see they are not equal
18th May 2020, 9:46 AM
Slick
Slick - avatar
+ 4
This is because l.sort() did not return any value thus, "a" is uninitialised.
18th May 2020, 9:50 AM
Arsenic
Arsenic - avatar
+ 4
Run this: l= [ 1,9,65,88,40 ] a = l.sort () b= sorted (l) print('a =',a) print('b =',b) if a==b: print (1+1) else: print (0)
18th May 2020, 9:53 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 4
Arsenic My internet is a bit slow, like me. By the time I posted, you gurus had already supplied the perfect answers
18th May 2020, 9:57 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
Rik Wittkopp this is what my code is doing.
18th May 2020, 9:53 AM
Arsenic
Arsenic - avatar
+ 2
Why it is showing NONE for print(a)
18th May 2020, 9:49 AM
Teja Swaroop
Teja Swaroop - avatar