python - Extract tuple from list -
i have list: [(hello(21,15),'now')] tuple inside list, , want extract tuple way output
(hello(21,15,'now')
just do:
lst[0]
to first element since list indices start @ 0
examples
>>> = [1,2,3] >>> a[0] 1 >>> a[2] 3
your case
>>> = [(hello(21,15),'now')] >>> a[0] (hello(21,15), 'now')
if further want 'now'
text do:
>>> a[0][1] 'now'
extension
if want range of values list, can use [:]
follows:
>>> = [1,2,3,4,5,6,7,8] >>> a[2:6] #this gets elements index 2 5 [3,4,5,6] >>> a[-1] #this gets last element of list 8
Comments
Post a Comment