I am currently working with different input types -
My input could either look like this:
[term1, term2, term3,...]
or
[[term1, term2], term3]
or
[[term1, term2], [term3, term4]]
I would like to find a way to flatten it to a format over which I could loop in order to use the terms.
My code at the moment looks like this:
for entry in initial_list:
if type(entry) is str:
do_something(entry)
elif type(entry) is list:
for term in entry:
do_something(term)
The goal would be to perform the flattening in a more Pythonic way, using list comprehension or mapping, instead of explicit for loops.