Dict python 의 마지막 요소

코드 예제

110
0

목록의 파이썬 마지막 요소

# To get the last element in a list you use -1 as position
bikes = ['trek', 'redline', 'giant']
bikes[-1]
# Output:
# 'giant'
2
0

사전 파이썬의 마지막 요소 가져 오기

list(dict)[-1]
1
0

마지막 요소를 제외한 파이썬 목록

>>> myList = list(range(1,5))
>>> myList
[1, 2, 3, 4]
>>> myList = myList[:-1]
>>> myList
[1, 2, 3]
-1
0

파이썬은 사전에서 마지막 가져 오기

# 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)

비슷한 페이지

예제가있는 유사한 페이지

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................