+ 12
[ASSIGNMENT] Sort a string with special rules
Given a string with numbers and characters. Sort that string so that characters are sorted in ascending order and numbers in descending order. characters and numbers as groups keep their places. Example a1bc32 -> a3bc21 Have Fun
23 Answers
+ 7
example solution python
https://code.sololearn.com/c1E10EEa90hz
+ 6
My try is here, thanks @VcC for table idea
https://code.sololearn.com/cI07NUjpY4RU/?ref=app
+ 5
@Tim... I was born in the sixties(-;
+ 4
how about symbols? Should they come before or after letters?
+ 4
@jonathan treat symbols like characters.
We have two groups:
numbers/nonNumbers
+ 4
Tried now in Kotlin
https://code.sololearn.com/cFwKd8WkcKGr
+ 3
heres it...just hurried so its not a one liner
https://code.sololearn.com/cC8LRFqUhy46/?ref=app
+ 3
@Oma
In your question you say
"characters and numbers as groups keep their places."
yet in the example you show
Example
a1bc32 -> a3bc21
is 32 not a number group?
+ 2
this is your homework?
+ 2
@VcC How will this keep numbers on a number place?
+ 2
My version:
https://code.sololearn.com/cvrlWfScxpo2/?ref=app
+ 1
So I just have to follow their ascii values?
+ 1
the code now uses only one array...
bit smaller##edited
+ 1
@vcc it is a bit tricky.,,
+ 1
@oma use a table giving the priority of ezch char then key=lambda c:table.index(c)
+ 1
Simple commented code. Would love comments =)
https://code.sololearn.com/c3a58v5cke0b/?ref=app
0
Python: sorted(s,key=whatever you want)