Python ile Türkçe Sıralama
Videoda ele aldığımığım kaynak kodları aşağıda paylaşıyorum:
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import locale def kucukharfyap(s): s1 = s.replace('İ', 'i') s1 = s1.replace('I', 'ı') return(s1.lower()) def buyukharfyap(s): s1 = s.replace('ı', 'I') s1 = s1.replace('i', 'İ') return(s1.upper()) print(locale.getlocale()) locale.setlocale(locale.LC_ALL, "tr_TR.UTF-8") print(locale.getlocale()) liste = ['zeytin', 'ıslak', 'şemsiye', 'Çanakkale', 'çaydanlık', 'ağaç', 'Öğretmen', 'öcü', 'üzengi', 'Üsküdar', 'Isparta', 'İstanbul', 'iğne'] lliste1 = [e.lower() for e in liste] uliste1 = [e.upper() for e in liste] lliste = [kucukharfyap(e) for e in liste] uliste = [buyukharfyap(e) for e in liste] print("liste : ", liste) print() print("lliste1: ", lliste1) print("lliste : ", lliste) print("uliste1: ", uliste1) print("uliste : ", uliste) print() print("sorted() -------------------------") print(sorted(liste)) print(sorted(lliste)) print(sorted(uliste)) print() print("sorted(l,key=locale.strxfrm) -----") print(sorted(liste, key=locale.strxfrm)) print(sorted(lliste, key=locale.strxfrm)) print(sorted(uliste, key=locale.strxfrm)) |
Ahmet Aksoy