I have a list of dictionaries:
some_list = [
{
item1:'a',
item2:['1', '2']
},
{
item1:'b',
item2:['1', '2']
},
{
item1:'a',
item2:['1']
}
]
I would like to get:
['a 1', 'a 2', 'b 1', 'b 2'], where each value from paragraph 1 is associated with the value from paragraph 2 for each dictionary, and then only unique lines remain.
I can imagine an obvious way to do this, namely:
- iteration through some_list;
- for each dictionary, get each ['item_1'] and each ['item_2']
- for each of ['item_2'] do each ['item_1'] + '' + member
- Now make the list into a set, and I have my own unique values.
I am wondering if this is a more elegant way to do this using list comprehension.