Solved

Arranging data in a list

Posted on 2006-07-05
2
237 Views
Last Modified: 2010-04-16
Hi,

This question is related to a previous question that was excellently answered:

http://www.experts-exchange.com/Programming/Programming_Languages/Python/Q_21905315.html



What I now would like to do is to create a list of the following structure:
[GarageName*Make-Model , GarageName*Make-Model , GarageName*Make-Model ...... ]

I have no problem making a list of the following structure:
[[GarageName, Make, Model] , [GarageName, Make, Model] , [GarageName, Make, Model] .....]


, but I need the cars to be in the first list format, as this is the format that they appear in another inventory.

So I need to use some kind of string function that will convert the object values to a string??


Hope you can help,
John
0
Comment
Question by:JohnAutoSales
2 Comments
 
LVL 14

Accepted Solution

by:
RichieHindle earned 500 total points
Comment Utility
How about this:

LIST = [["wood road", "toyota", "yaris"], ["john street", "ford", "mondeo"]]
result = ["%s*%s-%s" % (garage, make, model) for garage, make, model in LIST]
print result
0
 

Author Comment

by:JohnAutoSales
Comment Utility
Perfect!!

Thank you.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now