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

knan
0
Light Poster

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

Jump to Posttemp=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;

woooee
814
Nearly a Posting Maven

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 because:
*
n/a *

TrustyTony
888
pyMod
Team Colleague
Featured Poster

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

utpalendu
0
Newbie Poster

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;

Gribouillis
1,391
Programming Explorer
Team Colleague

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;
```

knan
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, learning, and sharing knowledge.

Broken Link

**You're trying to visit a URL that doesn't currently exist on the web.**
Most likely, a member posted a link a long time ago to a web page that has since been removed.
It's also possible that there was a typo when posting the URL.
We redirect you to this notice instead of stripping out the link to preserve the integrity of the post.