I have a list of dictionaries and in each of the dictionaries, I have a property that contains a list of ids. so I need to get the content of my properties as a new list . I tried to do this by inline for loop syntax . but I get this result :
my_list = [{"sessions": [1,2,3,42,56]}, {"sessions": [1,52,53,4,55]},{"sessions": [1,4,5]}]
listed_sessions =[ s for s in [j["sessions"] for j in my_list for item in j]]
print(listed_sessions)
result :
[[1, 2, 3, 42, 56], [1, 52, 53, 4, 55], [1, 4, 5]]
I mixed two different for loop as you can see. but I need to know, how can I get my result in a flat list?