목록의 파이썬 마지막 요소
# To get the last element in a list you use -1 as position
bikes = ['trek', 'redline', 'giant']
bikes[-1]
# Output:
# 'giant'
사전 파이썬의 마지막 요소 가져 오기
list(dict)[-1]
마지막 요소를 제외한 파이썬 목록
>>> myList = list(range(1,5))
>>> myList
[1, 2, 3, 4]
>>> myList = myList[:-1]
>>> myList
[1, 2, 3]
파이썬은 사전에서 마지막 가져 오기
# import the right class
from collections import OrderedDict
# create and fill the dictionary
d = OrderedDict()
d['first'] = 1
d['second'] = 2
d['third'] = 3
# retrieve key/value pairs
els = list(d.items()) # explicitly convert to a list, in case it's Python 3.x
# get first inserted element
els[0]
=> ('first', 1)
# get last inserted element
els[-1]
=> ('third', 3)