-4

I am new to python and I am just beginning to learn the syntax. I would like to create a map (like in java but I understand that they may be called something else in python) so I would assume the code might look something like this

map = {}
map.append("somestring": 12)
map.append("anotherstring": 10)
map.append("yetanotherstring": 15)
'''
then organize the map by the numbers from largest to smallest
so if I were to then run through the map with a for loop it would
print 
"yetanotherString" : 15
"somestring" : 12
"anotherstring" : 10
'''

I am clueless In almost every step of this process from declaring a "map" to organizing it by the ints. Though organizing it by the ints is my biggest problem.

  • If you’re new to Python, then please spend some time with [the tutorial](https://docs.python.org/3/tutorial/index.html). In your case, you are looking for [dictionaries](https://docs.python.org/3/tutorial/datastructures.html#dictionaries). – poke Jun 06 '16 at 18:16
  • Please don't name your variable `map` because you overwrite the built-in [`map`](https://docs.python.org/3/library/functions.html#map) function. – Matthias Jun 07 '16 at 07:55

1 Answers1

1

They're called dictionaries!

Try like this:

pythonDict = {}

pythonDict['somestring'] = 12

See more in http://learnpythonthehardway.org/book/ex39.html

To learn more about iterating through the dictionary see https://docs.python.org/2/library/itertools.html

Daniil Ryzhkov
  • 7,416
  • 2
  • 41
  • 58
Caio Tomazelli
  • 513
  • 5
  • 14