Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

subset a list python

# Creating a subset including elements at indexes 0, 1, 2, 4, 6, 7, 8
a = ['a', 'b', 'c', 3, 4, 'd', 6, 7, 8]
# List of indexes
b= [0, 1, 2, 4, 6, 7, 8]
# Create subset
c = [a[i] for i in b] # alternatively, c = a[0:2] + [a[4]] + a[6:]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #subset #list #python
ADD COMMENT
Topic
Name
2+3 =