Creating a single list

A

Astley Le Jasper

This is probably a really silly question but, given the example code
at the bottom, how would I get a single list?

What I currently get is:

('id', 20, 'integer')
('companyname', 50, 'text')
[('focus', 30, 'text'), ('fiesta', 30, 'text'), ('mondeo', 30,
'text'), ('puma', 30, 'text')]
('contact', 50, 'text')
('email', 50, 'text')

what I would like is:

('id', 20, 'integer')
('companyname', 50, 'text')
('focus', 30, 'text'),
('fiesta', 30, 'text'),
('mondeo', 30, 'text'),
('puma', 30, 'text'),
('contact', 50, 'text')
('email', 50, 'text')

SAMPLE CODE>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
def getproducts():
temp_list=[]
product_list=['focus','fiesta','mondeo','puma'] #usually this
would come from a db
for p in product_list:
temp_list.append((p,30,'text'))
return temp_list

def createlist():
column_title_list = (
("id",20,"integer"),
("companyname",50,"text"),
getproducts(),
("contact",50,"text"),
("email",50,"text"),
)
return column_title_list

for item in createlist():
print item
 
A

Astley Le Jasper

Astley Le Jasper ha scritto:


This is probably a really silly question but, given the example code
at the bottom, how would I get a single list?
What I currently get is:
('id', 20, 'integer')
('companyname', 50, 'text')
[('focus', 30, 'text'), ('fiesta', 30, 'text'), ('mondeo', 30,
'text'), ('puma', 30, 'text')]
('contact', 50, 'text')
('email', 50, 'text')
what I would like is:
('id', 20, 'integer')
('companyname', 50, 'text')
('focus', 30, 'text'),
('fiesta', 30, 'text'),
('mondeo', 30, 'text'),
('puma', 30, 'text'),
('contact', 50, 'text')
('email', 50, 'text')
SAMPLE CODE>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
def getproducts():
    temp_list=[]
    product_list=['focus','fiesta','mondeo','puma'] #usually this
would come from a db
    for p in product_list:
        temp_list.append((p,30,'text'))
    return temp_list
def createlist():
    column_title_list = (
                                    ("id",20,"integer"),
                                    ("companyname",50,"text"),
                                    getproducts(),
                                    ("contact",50,"text"),
                                    ("email",50,"text"),
                                )
    return column_title_list
for item in createlist():
    print item

 >>> def createlist():
...     column_title_list = [
...                                     ("id",20,"integer"),
...                                     ("companyname",50,"text")]
...     column_title_list += getproducts()
...     column_title_list += [
...                                     ("contact",50,"text"),
...                                     ("email",50,"text")]
...     return column_title_list
...
 >>> for item in createlist():
...     print item
...
('id', 20, 'integer')
('companyname', 50, 'text')
('focus', 30, 'text')
('fiesta', 30, 'text')
('mondeo', 30, 'text')
('puma', 30, 'text')
('contact', 50, 'text')
('email', 50, 'text')
 >>>

bye

Cheers for that. I was thinking there might be something clever, but
as usual, simple is better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,478
Latest member
ReginaldVi

Latest Threads

Top