I am trying to figure out how to best create a python dictionary where the values are variable names
e.x.
ruleLst = ["gender+brand","sport+gender","sport+gender+brand"]
for i in ruleLst:
new_values = i.split("+")
rules.update({i:new_values})
rules
returns:
{
'gender+brand': ['gender', 'brand'],
'sport+gender': ['sport', 'gender'],
'sport+gender+brand': ['sport', 'gender', 'brand']
}
What I try to output is:
{
'gender+brand': [gender, brand],
'sport+gender': [sport, gender],
'sport+gender+brand': [sport, gender, brand]
}
Where gender
, brand
, sport
are lists defined in the code before ruleLst
is defined.
You can use list comprehension like:
and output:
Reference: