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??

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]

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
'''

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;

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;
commented: Omg! Thank you so much! Ur a saviour... tyvm :) :) +1
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.