In Python list comprehension is it possible to access the item index?
If you use enumerate
, you do have access to the index:
list2 = [x for ind, x in enumerate(list1) if 4>ind>0]
list2 = [x for ind, x in enumerate(list1) if 4 > ind > 0]
If you use enumerate
, you do have access to the index:
list2 = [x for ind, x in enumerate(list1) if 4>ind>0]
list2 = [x for ind, x in enumerate(list1) if 4 > ind > 0]