거의 같다, 다만 sorted는 새로운 리스트를 만들 때 사용.
a = ["a", "d", "z", "D", "H"]
b = ['blue', 'yellow', 'red', 'Green', 'Orange']
a.sort(key=str.lower)
b2 = sorted(b, reverse=True, key=str.lower)
print(a)
print(b2)
['a', 'd', 'D', 'H', 'z']
['yellow', 'red', 'Orange', 'Green', 'blue']
countries = {"KOREA":"SEOUL", "USA":"DC", "CHINA":"BEIJING"}
print(countries.keys()) #key들만 추출
print(countries.values()) #value 들만 추출
print(countries.items()) #key-value추출
>>> countries = {"KOR":"seoul", "GERMANY":"berlin", "FRANCE":"paris"}
>>> a = sorted(countries)
>>> a
['FRANCE', 'GERMANY', 'KOR']
a = sorted(countries.items())
>>> a
[('FRANCE', 'paris'), ('GERMANY', 'berlin'), ('KOR', 'seoul')]
>>> a = sorted(countries.items(), reverse=True)
>>> a
[('KOR', 'seoul'), ('GERMANY', 'berlin'), ('FRANCE', 'paris')]
>>> def f1(x):
... return x[0]
>>> def f2(x):
... return x[1]
>>> a = sorted(countries.items(), key=f2)
>>> a
[('GERMANY', 'berlin'), ('FRANCE', 'paris'), ('KOR', 'seoul')]
>>> a = sorted(countries.items(), key=f1, reverse=True)
>>> a
[('KOR', 'seoul'), ('GERMANY', 'berlin'), ('FRANCE', 'paris')]
-클립보드에 무언가를 저장
pip install pyperclip
import pyperclip
pyperclip.copy("hi")
pyperclip.paste()
"hi"