출처 - https://www.w3schools.com/python/python_lists_methods.asp
출처 - https://dailyheumsi.tistory.com/67
Method | Description |
---|---|
append() | Adds an element at the end of the list |
clear() | Removes all the elements from the list |
copy() | Returns a copy of the list |
count() | Returns the number of elements with the specified value |
extend() | Add the elements of a list (or any iterable), to the end of the current list |
index() | Returns the index of the first element with the specified value |
insert() | Adds an element at the specified position |
pop() | Removes the element at the specified position |
remove() | Removes the item with the specified value |
reverse() | Reverses the order of the list |
sort() | Sorts the list |
>>> m = '나는 파이썬을 잘하고 싶다'
>>> m = m.split()
>>> m
['나는', '파이썬을', '잘하고', '싶다']
>>> m.sort(key=len) #길이를 기준으로 오름차순 정렬
>>> m
['나는', '싶다', '잘하고', '파이썬을']
#람다식을 이용해 key를 설정할 수 있다. (아이템 첫번째 인자를 기준으로 오름차순 정렬한다)
a = [(1, 2), (0, 1), (5, 1), (5, 2), (3, 0)]
c= sorted(a, key = lambda x : x[0])
>>>c
[(0, 1), (1, 2), (3, 0), (5, 1), (5, 2)]