forked from fluentpython/example-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting.py
More file actions
26 lines (14 loc) · 648 Bytes
/
sorting.py
File metadata and controls
26 lines (14 loc) · 648 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import locale
def check(sorted_list):
return 'CORRECT' if fruits == sorted_list else 'WRONG'
fruits = ['açaí', 'acerola', 'atemoia', 'cajá', 'caju']
print(locale.getlocale(locale.LC_COLLATE))
print('manual_sort ', fruits)
plain_sort = sorted(fruits)
print('plain_sort ', plain_sort, check(plain_sort))
locale_sort1 = sorted(fruits, key=locale.strxfrm)
print('locale_sort1', locale_sort1, check(locale_sort1))
locale.setlocale(locale.LC_COLLATE, 'pt_BR.UTF-8')
print('locale set to:', locale.getlocale(locale.LC_COLLATE))
locale_sort2 = sorted(fruits, key=locale.strxfrm)
print('locale_sort2', locale_sort2, check(locale_sort2))