@reagentx/

List of Lists

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Tag():
    def __init__(self, id=0, name=''):
        self.name = name
        self.id=id

    def __repr__(self):
        return f'Tag(id={self.id}, name=\"{self.name}")>'

tags = [[Tag(id=4, name="Lunch"), Tag(id=2, name="Dinner")], [Tag(id=165, name="Californian"), Tag(id=192, name="Cuban")], [Tag(id=350, name="Stewed")], [Tag(id=327, name="Served Hot")], [Tag(id=44, name="Chicken")], [Tag(id=291, name="Savory")], [Tag(id=295, name="Moist"), Tag(id=289, name="Tender")]]

tag_list = [tag for sublist in tags for tag in sublist]
print(tag_list, '\n')
print(len(tag_list), 'items')

def flatten(lst):
    out_l = []
    for item in lst:
        if isinstance(item, int):
            out_l.append(item)
        elif isinstance(item, list):
            out_l += flatten(item)
    return out_l