0

Sort method not working

https://code.sololearn.com/cdLuB8MO7MYo/?ref=app In last programme sort method/reverse sort method not working. Please help

31st May 2020, 8:02 PM
Neeraj Sharma
Neeraj Sharma - avatar
10 Respostas
+ 9
The code is working in python as well in ruby, with 2 small differences: (1) python problem: bikes.append('suzuki', 'hayabusa') append can only take 1 argument, but 2 are given. use this instead: bikes.extend(['suzuki', 'hayabusa']) (2) ruby problem: cars.sort(reverse = True). -> this has to be: cars.sort.reverse.
31st May 2020, 8:26 PM
Lothar
Lothar - avatar
+ 5
Mikhail Malyshev, what you mentioned for reverse sorting with cars[::-1] does not give a correct result. What it returnes is a "reversed sequence" of the list car, but NOT a sorted / reversed output. cars = ['toyota', 'bmw', 'audi', 'creta'] print(cars) cars.sort(reverse = True) print(cars) # output is: ['toyota', 'creta', 'bmw', 'audi'] # your suggestion with cars[::-1] gives a result of: cars = ['toyota', 'bmw', 'audi', 'creta'] print(cars[::-1]) # ['creta', 'audi', 'bmw', 'toyota']
3rd Jun 2020, 6:13 AM
Lothar
Lothar - avatar
+ 4
Sort is working as it should. You have the list ['toyota', 'bmw', 'audi', 'creta'] and then it will be sorted in descending order, as reverse is set to True. Result is ['toyota', 'creta', 'bmw', 'audi'].
31st May 2020, 8:14 PM
Lothar
Lothar - avatar
+ 2
In python cars.sort(reverse=True) will work fine
31st May 2020, 8:14 PM
Abhay
Abhay - avatar
+ 1
It is Ruby and for reverse sorting ,you need to do this cars.sort!{|a,b| b<=>a}
31st May 2020, 8:13 PM
Abhay
Abhay - avatar
+ 1
Sort isn't working as he said but it won't since its Ruby 𝐊𝐱𝐱𝐛𝐹 𝐆𝐡𝐚đČđšđ„ and cars.sort(reverse=True) is a python method for reversing list
31st May 2020, 8:17 PM
Abhay
Abhay - avatar
+ 1
Sorry fir the confusion guys i am very begginner and its my mistake instead of coding in python i have codes in ruby i appolozise for my mistake 𝐊𝐱𝐱𝐛𝐹 𝐆𝐡𝐚đČđšđ„ Abhay
31st May 2020, 8:22 PM
Neeraj Sharma
Neeraj Sharma - avatar
0
Ace still not working
31st May 2020, 8:13 PM
Neeraj Sharma
Neeraj Sharma - avatar
0
Look at my answers above and look where Neeraj Sharma is coding ,it's Ruby tho he is taking about python , and that won't work in ruby
31st May 2020, 8:19 PM
Abhay
Abhay - avatar
0
In append() method You have to pass only one argument. You coded as bikes.append('suzuki', 'hayabusa') Instead of above you should append the elements by a list or single string through it. Ex bikes.append(['suzuki','hayabusa']) or bikes.append('suzuki') bikes.append('hayabusa')
2nd Jun 2020, 1:24 PM
Purushoth
Purushoth - avatar