[issue34016] Bug in sort()

2018-07-01 Thread Lucas Sampaio


Lucas Sampaio  added the comment:

ok, I got it

lista4 = input().split()
print(lista4)
lista4.sort()
print(lista4)

print(type(lista4[2]))

 6 8 10['6', '8', '10']
['10', '6', '8']


ok, I got it

2018-07-01 18:05 GMT-03:00 Tim Peters :

>
> Tim Peters  added the comment:
>
> Lucas, as Mark said you're sorting _strings_ here, not sorting integers.
> Please study his reply.  As strings, "10" is less than "9", because "1" is
> less than "9".
>
> >>> "10" < "9"
> True
> >>> 10 < 9
> False
>
> --
> nosy: +tim.peters
>
> ___
> Python tracker 
> 
> ___
>

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34016] Bug in sort()

2018-07-01 Thread Tim Peters


Tim Peters  added the comment:

Lucas, as Mark said you're sorting _strings_ here, not sorting integers.  
Please study his reply.  As strings, "10" is less than "9", because "1" is less 
than "9".

>>> "10" < "9"
True
>>> 10 < 9
False

--
nosy: +tim.peters

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34016] Bug in sort()

2018-07-01 Thread Lucas Sampaio


Lucas Sampaio  added the comment:

same code with another input
type is list

lista4 = input().split()
print(lista4)
lista4.sort()
print(lista4)

 6 8 9
['6', '8', '9']
['6', '8', '9']


lista4 = input().split()
print(lista4)
lista4.sort()
print(lista4)

 10 11 12
 
['10', '11', '12']
['10', '11', '12']

but if you put a 9 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34016] Bug in sort()

2018-07-01 Thread Mark Dickinson


Mark Dickinson  added the comment:

This isn't a bug: I'm guessing that you expected an output of `['6', '8', 
'10']`, but in the example you give you're sorting strings rather than numbers, 
and those strings are sorted lexicographically (i.e., using "dictionary order") 
as normal.

If you want to do a numeric sort, convert your inputs to numbers first.

>>> lista4 = ['6', '8', '10']
>>> lista4_numbers = [int(s) for s in lista4]
>>> lista4_numbers.sort()
>>> lista4_numbers
[6, 8, 10]

--
nosy: +mark.dickinson
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34016] Bug in sort()

2018-07-01 Thread Lucas Sampaio


New submission from Lucas Sampaio :

lista4 = input().split()
print(lista4)
lista4.sort()
print(lista4)

Input = 6 8 10

Output:
 6 8 10
['6', '8', '10']
['10', '6', '8']

a bug occurs when setting the 10

--
messages: 320843
nosy: lucassdssampaio
priority: normal
severity: normal
status: open
title: Bug in sort()
type: behavior
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com