Skip to content

Commit f8aa905

Browse files
committed
Create sort_fractions.py
1 parent efe973c commit f8aa905

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

sort_fractions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from random import uniform
2+
nums = [round(uniform(0, 1000), 3) for _ in range(100)]
3+
4+
# Sort nums using only the fractional portion of each number.
5+
# Example: 30.12 is bigger than 100.01
6+
7+
def sort_fractional(nums):
8+
nums = map(str, nums)
9+
for i, num in enumerate(nums):
10+
index = num.find('.')
11+
nums[i] = num[index+1:]
12+
return sorted(nums)
13+
14+
print sort_fractional(nums)

0 commit comments

Comments
 (0)