Search
 
SCRIPT & CODE EXAMPLE
 

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:]
Comment

PREVIOUS NEXT
Code Example
Python :: python array slice 
Python :: multiple lines input python 
Python :: at=error code=H10 desc="App crashed" django 
Python :: django admin 
Python :: pandas dataframe.to_dict 
Python :: .describe() python 
Python :: python replace 
Python :: tkinter window size position 
Python :: python pop 
Python :: new column with multiple conditions 
Python :: transpose of list in python 
Python :: Generate 3 random integers between 100 and 999 which is divisible by 5 
Python :: Sum items in a list with ints and strings in python 
Python :: Read JSON files with automatic schema inference 
Python :: prolog avg of list 
Python :: rasperry pi camera 
Python :: if string is in array python 
Python :: can only concatenate str (not "int") to str 
Python :: turtle keep window open 
Python :: uppercase string python 
Python :: github python api 
Python :: # write json file 
Python :: use of kwargs and args in python classes 
Python :: driver code in python 
Python :: Python Tkinter Text Widget Syntax 
Python :: how to know if the space button has been clicked in python pygame 
Python :: concatenate list of strings 
Python :: undefined in python 
Python :: find all occurrences of an element in a list python 
Python :: python 3.7.9 download 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =