+ 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

13th Feb 2018, 5:23 AM
Oma Falk
Oma Falk - avatar
23 Answers
13th Feb 2018, 9:25 AM
LukArToDo
LukArToDo - avatar
13th Feb 2018, 6:41 AM
Oma Falk
Oma Falk - avatar
+ 6
My try is here, thanks @VcC for table idea https://code.sololearn.com/cI07NUjpY4RU/?ref=app
13th Feb 2018, 1:04 PM
Zoetic_Zeel
Zoetic_Zeel - avatar
+ 5
@Tim... I was born in the sixties(-;
13th Feb 2018, 5:33 AM
Oma Falk
Oma Falk - avatar
13th Feb 2018, 1:07 PM
wolfsan
wolfsan - avatar
+ 4
how about symbols? Should they come before or after letters?
13th Feb 2018, 5:42 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 4
@jonathan treat symbols like characters. We have two groups: numbers/nonNumbers
13th Feb 2018, 5:45 AM
Oma Falk
Oma Falk - avatar
13th Feb 2018, 8:17 AM
davy hermans
davy hermans - avatar
13th Feb 2018, 6:40 PM
Oma Falk
Oma Falk - avatar
+ 3
heres it...just hurried so its not a one liner https://code.sololearn.com/cC8LRFqUhy46/?ref=app
13th Feb 2018, 6:36 AM
sayan chandra
sayan chandra - avatar
+ 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?
13th Feb 2018, 6:47 AM
Louis
Louis - avatar
+ 2
this is your homework?
13th Feb 2018, 5:32 AM
Tim Millar
Tim Millar - avatar
+ 2
@VcC How will this keep numbers on a number place?
13th Feb 2018, 10:10 AM
Oma Falk
Oma Falk - avatar
13th Feb 2018, 6:05 PM
Paul
Paul - avatar
+ 1
So I just have to follow their ascii values?
13th Feb 2018, 5:48 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 1
the code now uses only one array... bit smaller##edited
13th Feb 2018, 6:41 AM
sayan chandra
sayan chandra - avatar
+ 1
@vcc it is a bit tricky.,,
13th Feb 2018, 9:03 AM
Oma Falk
Oma Falk - avatar
+ 1
@oma use a table giving the priority of ezch char then key=lambda c:table.index(c)
13th Feb 2018, 9:52 AM
VcC
VcC - avatar
+ 1
Simple commented code. Would love comments =) https://code.sololearn.com/c3a58v5cke0b/?ref=app
13th Feb 2018, 10:33 AM
Nitzan
Nitzan - avatar
0
Python: sorted(s,key=whatever you want)
13th Feb 2018, 6:34 AM
VcC
VcC - avatar