Solved

Storing dictionary values

Posted on 2006-06-29
1
277 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
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 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…
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…

624 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