Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Arranging data in a list

Posted on 2006-07-05
2
Medium Priority
?
246 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
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…

972 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