help me ?

Michael F. Stemper michael.stemper at gmail.com
Tue Feb 27 18:55:01 EST 2018


On 2018-02-26 07:17, Stefan Ram wrote:
> Percival John Hackworth <pjh at 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.



More information about the Python-list mailing list