Re: [Tutor] Help with putting numbers from highest to lowest.
On 27/09/2017 20:36, Derry, James R wrote: [Top posting fixed] From: Tutor [tutor-bounces+jderry=mail.utexas@python.org] on behalf of edmundo pierre via Tutor [tutor@python.org] Sent: Wednesday, September 27, 2017 8:10 AM To: Tutor Python Subject: [Tutor] Help with putting numbers from highest to lowest. Hello, When I used sort() to do that, but my problem is that sort() just arrange numbers from small to big, not from big to small. That is the issue I am having now. For instance: # The user is entering those numbers:a = 2.7b = 4.7c= 5.8d = 7.9# I will like the answer to be like this: 7.9 5.8 4.7 2.7 #but if I use sort(), I will have that answer, but I do not want that:2.7 4.7 5.8 7.9 Thank you! > In [2]: ?sorted Noting that this is iPython specific... > Signature: sorted(iterable, /, *, key=None, reverse=False) > Docstring: > Return a new list containing all items from the iterable in ascending order. > > A custom key function can be supplied to customize the sort order, and the > reverse flag can be set to request the result in descending order. > Type: builtin_function_or_method > > In [3]: sorted([3,1,5], reverse=True) > Out[3]: [5, 3, 1] ...as are all the In[x] and Out[y] bits and pieces. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email has been checked for viruses by AVG. http://www.avg.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with putting numbers from highest to lowest.
On 27/09/2017 14:10, edmundo pierre via Tutor wrote: Hello, When I used sort() to do that, but my problem is that sort() just arrange numbers from small to big, not from big to small. That is the issue I am having now. For instance: # The user is entering those numbers:a = 2.7b = 4.7c= 5.8d = 7.9# I will like the answer to be like this: 7.9 5.8 4.7 2.7 #but if I use sort(), I will have that answer, but I do not want that:2.7 4.7 5.8 7.9 Thank you! You need reverse=True on the call to sort. You can find this out by:- 1. Using the interactive interpreter help, e.g. >>> l = [2.7, 4.7, 5.8, 7.9] >>> help(l.sort) Help on built-in function sort: sort(*, key=None, reverse=False) method of builtins.list instance Stable sort *IN PLACE*. None 2. clicking `index` to the top right of https://docs.python.org/3/, then `s` then `(list method)` under `sort`. 3. using your favourite search engine. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email has been checked for viruses by AVG. http://www.avg.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with putting numbers from highest to lowest.
In [2]: ?sorted Signature: sorted(iterable, /, *, key=None, reverse=False) Docstring: Return a new list containing all items from the iterable in ascending order. A custom key function can be supplied to customize the sort order, and the reverse flag can be set to request the result in descending order. Type: builtin_function_or_method In [3]: sorted([3,1,5], reverse=True) Out[3]: [5, 3, 1] From: Tutor [tutor-bounces+jderry=mail.utexas@python.org] on behalf of edmundo pierre via Tutor [tutor@python.org] Sent: Wednesday, September 27, 2017 8:10 AM To: Tutor Python Subject: [Tutor] Help with putting numbers from highest to lowest. Hello, When I used sort() to do that, but my problem is that sort() just arrange numbers from small to big, not from big to small. That is the issue I am having now. For instance: # The user is entering those numbers:a = 2.7b = 4.7c= 5.8d = 7.9# I will like the answer to be like this: 7.9 5.8 4.7 2.7 #but if I use sort(), I will have that answer, but I do not want that:2.7 4.7 5.8 7.9 Thank you! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with putting numbers from highest to lowest.
edmundo pierre via Tutor schreef op 27/09/2017 15:10: Hello, When I used sort() to do that, but my problem is that sort() just arrange numbers from small to big, not from big to small. That is the issue I am having now. For instance: # The user is entering those numbers:a = 2.7b = 4.7c= 5.8d = 7.9# I will like the answer to be like this: 7.9 5.8 4.7 2.7 #but if I use sort(), I will have that answer, but I do not want that:2.7 4.7 5.8 7.9 You can reverse the sort order with reverse=True, like so: numbers = [7.9, 4.7, 2.7, 5.8] numbers.sort(reverse=True) print(numbers) --> [7.9, 5.8, 4.7, 2.7] See https://docs.python.org/3/library/stdtypes.html?highlight=sort#list.sort -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help with putting numbers from highest to lowest.
Hello, When I used sort() to do that, but my problem is that sort() just arrange numbers from small to big, not from big to small. That is the issue I am having now. For instance: # The user is entering those numbers:a = 2.7b = 4.7c= 5.8d = 7.9# I will like the answer to be like this: 7.9 5.8 4.7 2.7 #but if I use sort(), I will have that answer, but I do not want that:2.7 4.7 5.8 7.9 Thank you! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor