-2

i have some lists with str(numbers) for example ['8', '0', '9', '5', '7'], ['8', '0', '9', '5', '7'] need to join each element from first list with each element from second list ['88','80','89','85','87','08'...] the number of lists can be up to 100

firstly i think to use itertools.product(), but I didn't manage to implement it

  • 4
    You said you tried `itertools.product` -- did you `join` the products together? e.g. `[''.join(p) for p in itertools.product(first_list, second_list)]` If that didn't work, what was missing from the output that you were hoping to get? – Samwise Mar 15 '23 at 14:57
  • 1
    See [Python convert tuple to string](https://stackoverflow.com/q/19641579/6045800) if you are actually using `product` – Tomerikoo Mar 15 '23 at 15:06

2 Answers2

0

try:

L= ['8', '0', '9', '5', '7']
B=['8', '0', '9', '5', '7'] 
your_list=[i+j for i in L for j in B]
Mouad Slimane
  • 913
  • 3
  • 12
0
l1, l2 = ['8', '0', '9', '5', '7'], ['8', '0', '9', '5', '7']

import itertools

print([''.join(pair) for pair in itertools.product(l1, l2)])
matszwecja
  • 6,357
  • 2
  • 10
  • 17