How to get items in specific index range of a list using sequence operator as function in Python

1 Answer

0 votes
from operator import *    
 
a = [0, 3, 1, 6, 2, 3, 4, 6, 3]     
b = ['x', 'b', 'a', 'z', 'c', 'a']
c = ['c++', 'python', 'php', 'java', 'php']
 
print(getitem(a, slice(1, 4)))

print(getitem(b, slice(0, 2)))

print(getitem(c, slice(0, 3)))


 
'''
run:
 
[3, 1, 6]
['x', 'b']
['c++', 'python', 'php']

'''

 



answered May 31, 2019 by avibootz
...