Explanation please??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Explanation please???

here is someone's code and i don't know what lines of code 8-10 mean plz explain!!! if n == 0: return 0 s = ''.join(sorted(str(n))) c = s.count('0') s = s.replace('0', '') if s[0] != '-': s = s[0] + '0' * c + s[1:] else: s = s[:2] + '0' * c + s[2:] return int(s) print(s)

12th Jun 2021, 6:00 AM
Ailana
Ailana - avatar
4 Answers
+ 5
Post the whole code.
12th Jun 2021, 6:36 AM
TOLUENE
TOLUENE - avatar
0
Here is the whole code: def min_permutation(n): if n == 0: return 0 s = ''.join(sorted(str(n))) c = s.count('0') s = s.replace('0', '') if s[0] != '-': s = s[0] + '0' * c + s[1:] else: s = s[:2] + '0' * c + s[2:] return int(s) print(s)
12th Jun 2021, 4:23 PM
Ailana
Ailana - avatar
0
Given a number, find the permutation with the smallest absolute value (no leading zeros). -20 => -20 -32 => -23 0 => 0 10 => 10 29394 => 23499 The input will always be an integer.
12th Jun 2021, 6:07 PM
Ailana
Ailana - avatar
0
Thank you for not replying :)
13th Jun 2021, 2:06 AM
Ailana
Ailana - avatar