How to multiply all possible number combinations between two lists


#1

THERE IS A SIMPLE QUESTION THAT TRUBLES ME A LOT. IF I HAVE TWO LISTS, EACH OF WHICH IS A RANGE OF NUMBERS, HOW CAN I MULTIPLY ALL THE POSSIBLE NUMBER COMBINATIONS?

THAT’S THE CODE I HAVE TYPED SO FAR…

alist = []
blist = []

for i in range(100, 1000):
alist.append(i)
blist.append(i)

NOTE: I AM USING PYTHON 2, IF THAT MATTERS.

I’D APPRECIATE ANY ADVICE!


#2

yippie, data matrix’s.

so lets say you have:

alist = [1, 2, 3]
blist = [4, 5, 6]

you want to get:

[4, 5, 6, 8, 10, 12, 12, 15, 18]

or:

[[4, 5, 6], [8, 10, 12], 12, 15, 18]]

? There are multiple possibilities.

this looks a bit redundant:

for i in range(100, 1000):
alist.append(i)
blist.append(i)

you can simple produce the list from range:

list(range(100, 1000))

or if you use python2, range will produce a list