Solved

Arranging data in a list

Posted on 2006-07-05
2
239 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
ID: 17045826
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
ID: 17046519
Perfect!!

Thank you.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
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 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 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 …

786 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