-2

So I have the following

Product     Customer
1           ABC Ltd
2           EFG Ltd
3           XYZ Ltd

I want to create a list that has all combinations, meaning,

Product     Customer
1           ABC Ltd
1           EFG Ltd
1           XYZ Ltd
2           ABC Ltd
2           EFG Ltd

.... and so on. I would be left with 9 entries in this eg. and also to be dynamic so it updates if added or changed.

Thanks

vlumi
  • 273

1 Answers1

1

Any basic set of nested for loops in any programming/scripting language can likely produce the results you desire. For instance, in Python:

#!/path/to/Python3/python

# lists of strings to concatenate
products = ['1', '2', '3']
companies = ['ABC Ltd', 'EFG Ltd', 'XYZ Ltd']

# Nested 'for' loops
for product in products:
    for company in companies:
        print (product, '\t', company)

Which produces the following output:

1    ABC Ltd
1    EFG Ltd
1    XYZ Ltd
2    ABC Ltd
2    EFG Ltd
2    XYZ Ltd
3    ABC Ltd
3    EFG Ltd
3    XYZ Ltd

The values for products and companies could be read dynamically from e.g. updated text files using for loops as well. Again, in Python:

# Replaces e.g
# products = ['1', '2', '3']
# companies = ['ABC Ltd', 'EFG Ltd', 'XYZ Ltd']

products = []
companies = []

with open ('products.txt', 'r') as products_file:
    for line in products_file:
        products.append(line.strip())

with open ('companies.txt', 'r') as companies_file:
    for line in companies_file:
        companies.append(line.strip())

ex. products.txt:

1
2
3

ex. companies.txt:

ABC Ltd
EFG Ltd
XYZ Ltd
Anaksunaman
  • 17,239