Solved

Storing dictionary values

Posted on 2006-06-29
1
273 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 500 total points
ID: 17014589
I think you want place = factoryloc[car].
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

763 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