-1

In python I have:

my_dict = dict({'98:1E:19:7E:8F:30': ['SAGEMCOM BROADBAND SAS', '22'], '98:1E:19:7E:8F:32': ['SAGEMCOM BROADBAND SAS1']})

and would like to generate a list of all values, so I tried:

[[sub_val for sub_val in val] for val in my_dict.values()]

But this gives me:

[['SAGEMCOM BROADBAND SAS', '22'], ['SAGEMCOM BROADBAND SAS1']]

while I wanted:

['SAGEMCOM BROADBAND SAS', '22', 'SAGEMCOM BROADBAND SAS1']

What's wrong with what I've done

zoro
  • 15
  • 5

1 Answers1

1

You can use an additional for clause in the list comprehension to iterate through the sub-lists:

[value for values in my_dict.values() for value in values]
blhsing
  • 91,368
  • 6
  • 71
  • 106
  • You are assuming each list has one item only... – zoro Nov 28 '22 at 01:26
  • 2
    In that case it's a question of flattening a nested list that has been answered for thousands of times and can be found with a search easily. – blhsing Nov 28 '22 at 01:31