0

I have a list of lists

x=[['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']]

I need the following output.

a-b
a-c
a-d
b-c
b-d
c-d
e-f
g-h

How can i do this? Can a regular expression be used here??

5
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Gribouillis
Featured Replies
  • temp=1 main_list = [['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']] for each_list in main_list: for ctr in range(len(each_list) - 1): temp=ctr +1 while temp < len(each_list) : print each_list[ctr],"-", each_list[temp ] temp = temp + 1; Read More

  • [QUOTE=utpalendu;1369445]temp=1 main_list = [['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']] for each_list in main_list: for ctr in range(len(each_list) - 1): temp=ctr +1 while temp < len(each_list) : print each_list[ctr],"-", each_list[temp ] temp = temp + 1;[/QUOTE] Please learn about code tags [url]http://www.daniweb.com/forums/announcement.php?f=8&announcementid=3[/url] See how better it looks: [code=python] main_list … Read More

0

A place to start, without coding the solution for you. Post your code for help with further problems.

main_list = [['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']]
for each_list in main_list:
    print "\n  New List"
    for ctr in range(len(each_list)):
        print ctr, each_list[ctr]

Edited by woooee: n/a

0

Find the mathematical base for what you want to do and find what is this function named mystery here in standard library (the import of module left out here):

from ____ import ____ as mystery
x=[['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']]
for sub in x:
    print list(mystery(sub,2))
print '\n'.join('-'.join(solution) _____)
'''Output:
[('a', 'b'), ('a', 'c'), ('a', 'd'), ('b', 'c'), ('b', 'd'), ('c', 'd')]
[('e', 'f')]
[('g', 'h')]
a-b
a-c
a-d
b-c
b-d
c-d
e-f
g-h
'''
1

temp=1
main_list = [['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']]
for each_list in main_list:
for ctr in range(len(each_list) - 1):
temp=ctr +1
while temp < len(each_list) :
print each_list[ctr],"-", each_list[temp ]
temp = temp + 1;

1

temp=1
main_list = [['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']]
for each_list in main_list:
for ctr in range(len(each_list) - 1):
temp=ctr +1
while temp < len(each_list) :
print each_list[ctr],"-", each_list[temp ]
temp = temp + 1;

Please learn about code tags http://www.daniweb.com/forums/announcement.php?f=8&announcementid=3
See how better it looks:

main_list = [['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']]
for each_list in main_list:
    for ctr in range(len(each_list) - 1): 
        temp=ctr +1
        while temp < len(each_list) : 
            print each_list[ctr],"-", each_list[temp ]
            temp = temp + 1;
Comments
Omg! Thank you so much! Ur a saviour... tyvm :) :)
This question has already been answered. 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.