hi,
I am using reportlab to generate pdf but having a problem in making list in tabular format.

final list should be in this format:
list =[ ,
,
,
]

data =[]
data.append('companies')
for item in some_list:
data.insert(0, item) -> Assuming item gives me values = 1, 2, 3
if industries:
data.insert(1, 'industries)
for item in some_list:
data.insert(1, item) -> Assuming item gives me values = 11, 22, 33

so my final data should be in above list format.
list =[ ,
,
,
]

How to implement it??? I know above code is wrong way of implementing it.

Can any one help me out
Thanks.

try this

some_list_A = [1, 2, 3]
some_list_B = [11, 12, 13]
li_A = ['companies'] + [str(item) for item in some_list_A]
li_B = ['industries'] + [str(item) for item in some_list_B]
print "li_A", li_A
print "li_B", li_B
li_C = zip(li_A, li_B)
print "li_C", li_C
data = [ list(item) for item in li_C ]
print "data", data

You want to use a counter, incremented by +1, to access that element of each one of the lists. This can be done in fewer lines of code but this is the easiest to understand.

combined_list = []
stop = len(list_1)
for ctr in range(0, stop):
     junk_list = []
     junk_list.append( list_1[ctr] )
     junk_list.append( list_2[ctr] )
     combined_list.append( junk_list )

I will leave it to you to insert the header lits as the first element, and decide what happens if the two lists are not the same length.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.