Answers for "how to display subset of list in python"

1

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:]
Posted by: Guest on January-30-2022
0

get all subsets of a list python

a_set = {"a", "b", 1, 2}
data = itertools.combinations(a_set, 2)
subsets = set(data)
print (subsets)
Posted by: Guest on April-20-2021

Code answers related to "how to display subset of list in python"

Python Answers by Framework

Browse Popular Code Answers by Language