0
Sort method not working
https://code.sololearn.com/cdLuB8MO7MYo/?ref=app In last programme sort method/reverse sort method not working. Please help
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.
+ 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']
+ 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'].
+ 2
In python cars.sort(reverse=True) will work fine
+ 1
It is Ruby and for reverse sorting ,you need to do this
cars.sort!{|a,b| b<=>a}
+ 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
+ 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
0
Ace still not working
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
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')