Dash Dropdown different variables for label and value

I have a dataframe with two columns (‘all_words’, ‘tags’) that I want to use respectively for the label and value of the dropdown.

all_words = df[‘words’]
tags = df[‘tags’]

options=[{‘label’: i,‘value’: x} for i in all_words, for x in tags],

This code doesn’t work, and my mistake may be obvious to someone else. I often see cases of using the same variable for both, e.g. [{‘label’: i,‘value’: i} for i in all_words], but never for different variables.

Anyone able to help?

Hi @lisni946

I’ve done something like this, and it’s worked for me:

options_dict = dict(zip(df['words'], df['tags']))

options = [{'label':word,'value':tag} for word, tag in options_dict.items()]
1 Like