0

I have a number of lists such as

I either need to make a list of lists or a dictionary containing lists. What would be the recommended one to do and will make the process of further sorting and text manipulation the easiest.

Thanks,

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by woooee
0

List is ordered and you mention sorting, so list of lists looks better. Difficult to tell without knowing more of your plans.

0

I have a loop which generates lists such as

Once all of this have been created within a list of dict I want to print them all out within correctly space|padded columns...

0

In the end Ive created a list of lists which looks like the following :

[['123', 19, '13', 'Fa0/19', '100000000'], ['13', 22, '13', 'Fa0/22', '100000000'], ['123', 19, '123', 'Fa0/19', '100000000']]

Can you confirm how the for loop would look if I wanted to go through each column by item ?

0

It is often usefull to do transpose and extract one of the columns which become own list, if you do not want simultanously to process all columns.

from pprint import pprint
info = [['123', 19, '13', 'Fa0/19', '100000000'], ['13', 22, '13', 'Fa0/22', '100000000'], ['123', 19, '123', 'Fa0/19', '100000000']]
print('Info')
pprint(info)
print('Transpose')
pprint(list(zip(*info)))
print('Fa by generator expression')
print(', '.join(fa for a, b, c, fa, d in info))
0

You can iterate through the list, taking each sub-list and printing the individual items within that sub-list.

test_list=[['123', 19, '13', 'Fa0/19', '100000000'],
           ['13', 22, '13', 'Fa0/22', '100000000'],
           ['123', 19, '123', 'Fa0/19', '100000000']]

for sub_list in test_list:
    print sub_list
    for ctr in range(len(sub_list)):
        print "     ", ctr, "-->", sub_list[ctr]
    print

Edited by woooee: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.