On 2018-02-26 07:17, Stefan Ram wrote:
Percival John Hackworth <p...@nanoworks.com> quoted:
Define 2 lists. The first one must contain the integer values 1, 2 and 3

a =[ 1, 2, 3 ]

and the second one the string values a, b and c.

b =[ 'a', 'b', 'c']

Iterate through both lists to create another list that
contains all the combinations of the A and B

for i in a:
     result = [ '1a', '1b', '1c', '2a', '2b', '2c', '3a', '3b', '3c' ]

for j in b:
     result = [ '1a', '1b', '1c', '2a', '2b', '2c', '3a', '3b', '3c' ]

That's absolutely wonderful!

However, I'd like to suggest one change, which would allow greater
CPU utilization:

for i in a:
  for j in b: # Sorry, I'm not PEP-8 compliant
    result = [ '1a', '1b', '1c', '2a', '2b', '2c', '3a', '3b', '3c' ]


--
Michael F. Stemper
Always remember that you are unique. Just like everyone else.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to