Well, I was convert it to string again, after I sorted numbers.
But, according to python docs:
**sort(): Strings are sorted alphabetically, and numbers are sorted numerically.**
So it's unnecessary to try to convert it to a number again. because sort() and sorted() do the same thing with integers and strings, but only if both are numbers.
What join() basically do is it takes all items in an list/array and joins them into one string separated by the whatever character you have specified in between the ' ' in ''.join().
Sometimes it can be an empty string which means all the items in the list will be joined and there will be no spaces in between them as shown in the code above you have shared.
Than you, for not convert it to numbers again.
Well, I was convert it to string again, after I sorted numbers.
But, according to python docs:
So it's unnecessary to try to convert it to a number again. because sort() and sorted() do the same thing with integers and strings, but only if both are numbers.
What
join()
basically do is it takes all items in an list/array and joins them into one string separated by the whatever character you have specified in between the' '
in''.join()
.Sometimes it can be an empty string which means all the items in the list will be joined and there will be no spaces in between them as shown in the code above you have shared.
For example :
This comment is hidden because it contains spoiler information about the solution
yes, s for s in x
Does this iterate over each letter in the string?
And you are right! Don't learn Python 2 except if you need a tierce library not compatible with Python 3.
This comment is hidden because it contains spoiler information about the solution
I precise this solution works only with Python 2, try to find why ;-)
I think I picked up about 3 tricks with that. Very nice and concise.
This comment is hidden because it contains spoiler information about the solution