help me ?

Igor Korot ikorot01 at gmail.com
Tue Feb 27 12:16:29 EST 2018


Hi,

On Tue, Feb 27, 2018 at 10:54 AM, Sir Real <nomail at adres.net> wrote:
> On Mon, 26 Feb 2018 01:40:16 -0800 (PST), sotaro237 at gmail.com wrote:
>
>>Define 2 lists. The first one must contain the integer values 1, 2 and 3 and the second one the string values a, b and c. Iterate through both lists to create another list that contains all the combinations of the A and B elements. The final list should look like one of the 2 lists:
>>1. [1a, 1b, 1c, 2a, 2b, 2c, 3a, 3b, 3c]
>>2. [a1, a2. a3, b1, b2, b3, c1, c2, c3]
>>BONUS: Make the final list contain all possible combinations : [1a, a1, 1b, b1, 1c, c1, 2a, a2, 2b, b2, 2c, c2, 3a, a3, 3b, b3, 3c, c3]
>>
>>Help me !
>
> #a list of integers
> nums = [1, 2, 3]
>
> #a list of letters
> ltrs = ['a', 'b', 'c']
>
> #a list to hold the result
> rslt = []
>
> for i in nums:
>     for j in ltrs:
>         rslt.append(str(i) + j)
>         #for bonus points uncomment the following line
>         #rslt.append(j + str(i))
>
> print(rslt)
>
>
> '''RESULT
> ['1a', '1b', '1c',
>  '2a', '2b', '2c',
>  '3a', '3b', '3c']
>
>    BONUS RESULT
> ['1a', 'a1', '1b', 'b1', '1c', 'c1',
>  '2a', 'a2', '2b', 'b2', '2c', 'c2',
>  '3a', 'a3', '3b', 'b3', '3c', 'c3']

Congratulations!
You have an "A" for solving the problem and "F" for helping the guy cheat.
You should be expelled from the course.

;-)

Thank you.

> '''
> --
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list