Solved

Storing dictionary values

Posted on 2006-06-29
1
263 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
1 Comment
 
LVL 17

Accepted Solution

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a…
Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now