Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Storing dictionary values

Posted on 2006-06-29
1
Medium Priority
?
279 Views
Last Modified: 2010-04-16

Hi,

This question relates to my previous question:
http://www.experts-exchange.com/Programming/Programming_Languages/Python/Q_21902718.html?qid=21902718

I now can store the values of the model attributes from all vehicle tags in my XML file in a list.

For each model value in the list, I need to find the coresponding country (stored in a dictionary) and put this into a new country list.

Please excuse my lack of Python skills, but I am picking it up.
What I have is this:

factoryloc = {"toyota":"japan", "fiat":"italy", "renault":"france", "chevrolet":"united states"}

vehicleLst = xmldoc.getElementsByTagName("vehicle")

myCarPark = []
for vehicle in vehicleLst:
      myCarPark.append(vehicle.getAttribute('make'))


carCountries = []

i = 0
for car in myCarPark:
    factoryloc["car[0]"] = place  ##I realise that this is wrong, but hopefully you will get the idea
    carCountries.append(place)


I know where I'm going wrong, but can't quite figure out how to link the list to the dictionary.


Thanks,
John
0
Comment
Question by:JohnAutoSales
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
ramrom earned 2000 total points
ID: 17014589
I think you want place = factoryloc[car].
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question