Maybe there was a better way to do this, but I have a list of mixed elements:
outlist = [10, [ETSc, Juniper Hairstreak], [ETSc, Spotted Turtle],
[ETSc, Blanding's Turtle], IWWH]
What I would like to do is iterate over this list and if the list element contains ETSc, then I want to convert it to a string like this:
ETSc (Juniper Hairstreak)
If it doesn’t contain ETSc then I just want to convert it to a string:
IWWH
Ultimately the strings will populate a variable in an access database table. But I have no idea how to tell Python to find the list elements containing ETSc, since some of the elements are lists within a list and some are just strings.
Any help is greatly appreciated!!
Something like this, using a list comprehension:
As @julio commented, you could make this more readable using a function: