Questions related to python list.sort().

Asked 2 years ago, Updated 2 years ago, 144 views

Group3 = list()
Group3.append('A')
Group3.append('Da')
Group3.append('la')
Group3.append('I')
Group3.append('c')
Group3.append('a')
Group3.append('b')
Group3.append('羅')
Group3.append('家')
Group3.append('多')
Group3.append('A')
Group3.append('F')
Group3.append('B')
Group3.sort()
print("If we slice Korean, English, and Chinese characters into Group 3 strings, will it be sorted?" >")
Slice1 = Group3[:3]
Slice2 = Group3[4:6]
Slice3 = Group3[7:9]
Slice4 = Group3[10:12]
Slice1.sort()
Slice2.sort()
Slice3.sort()
Slice4.sort()
print(Group3)

Expected value: ['A', 'B', 'F', 'a', 'b', 'c', 'family', '',', 'multi', 'ga', 'N', 'Da', 'La']

Results: ['A', 'B', 'F', 'a', 'b', 'c', 'multi', 'family', 'ga', 'N', 'Da', 'La', ''']

list sorting append slice python

2022-09-22 19:36

1 Answers

If you take an order function for a character character, it returns a number that is the unicode code point of the character. We will sort by this number.

>> l = ['A', 'B', 'F', 'a', 'b', 'c', 'multi', 'family', 'ga', 'N', 'Da', 'La', '',']
>>> list(map(ord, l))
[65, 66, 70, 97, 98, 99, 22810, 23478, 44032, 45208, 45796, 46972, 63759]
>>> 

Chinese characters are not only Korean characters that we think of, but also Chinese characters commonly used in Korea, China, Japan, and Vietnam, and they will be complexly defined in Unicode.

If you try to arrange it in the order of Korean reading of Chinese characters, it's a little ambiguous because the last letter "La" can be read as "La" or "Me"... Anyway), there is a package called hanja in Python, so if you use it and sort it to the value converted into Korean, it will be roughly what you want.

https://github.com/suminb/hanja


2022-09-22 19:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.