xxxxxxxxxx
#removing elements from nested lists
list[element].pop(nested_element)
xxxxxxxxxx
# If you know the index of the item you want, you can use the pop() method. It modifies the list and returns the removed item.
L = ['a', ['bb', 'cc', 'dd'], 'e']
x = L[1].pop(1)
print(L)
# Prints ['a', ['bb', 'dd'], 'e']
# removed item
print(x)
# Prints cc
xxxxxxxxxx
def flat(lis):
flatList = []
# Iterate with outer list
for element in lis:
if type(element) is list:
# Check if type is list than iterate through the sublist
for item in element:
flatList.append(item)
else:
flatList.append(element)
return flatList
lis = [[11, 22, 33, 44], [55, 66, 77], [88, 99, 100]]
print('List', lis)
print('Flat List', flat(lis))