Melanie432k Melanie432k - 1 year ago 82
Python Question

Inputting key words and their values on Python

Simple question. I tried to search it up but couldn't find much information about what Im trying to do.
Im trying to create a list with words and integer values and put them in the list together. For example,


Well i know how to put the words in a list, but not the values. So I did so far:
(Still using examples)
pyList = {'python', 'great, 'shine', rain}

So basically im trying to input the keywords and their values and store them in a list

Answer Source

A dictionary might be better than a list.

item_dict = {'rain': 10, 'shine': 5, 'python': 10, 'great': 1}

The following code


will output 10

If you don't care what numbers they have, but just want a different one for each then you can enumerate a list and turn that into a dictionary.

items = ['rain','shine','python','great']
items_dict = dict(enumerate(items))

This will give you a dictionary with the following values

{0: 'rain', 1: 'shine', 2: 'python', 3: 'great'}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download