I have a list of dictionaries with info in such format:
p_mat_list = [
{'name': 'Mirror', 'link': '/somelink1/'},
{'name': 'Gold Leaf', 'link': '/somelink2/'}
]
First, create python list with all name values:
product_materials = []
for material in p_mat_list:
product_materials.append(material['name'])
However, I don't know what would be best way to get all name values when list will have nested list(s) with dictionaries alongside, as below:
p_mat_list = [
[{'name': 'Painted'}, {'name': 'Wood'}],
{'name': 'Mirror'},
{'name': 'Gold Leaf'}
]
How can I get all these name values: Painted, Wood, Mirror, Gold Leaf?
Also, how could I approach merging name values from all dictionaries inside every nested list into one value and then get that into list with others, so would get such values: Painted Wood, Mirror, Gold Leaf.
There won't be lists nested more levels and no more than two dictionaries inside them, so for e.g. from this list below would need to get such values: Painted Wood, Mirror, Varnished Wood, Gold Leaf.
p_mat_list = [
[{'name': 'Painted'}, {'name': 'Wood'}],
{'name': 'Mirror'},
[{'name': 'Varnished'}, {'name': 'Wood'}],
{'name': 'Gold Leaf'}
]
'Painted Wood'as a single string, instead of'Painted'and'Wood'as separate strings? If so, it's inconsistent with your first example, and in that case I think we would need some more clarification on what you mean.