I have two lists

BOT_HELLO = ('привет', 'прив', 'дарова') BOT_NAMES = ('Джаред', 'Джар', 'бот') 

and I need to get a third list of this type at the output

 THIRD = ('привет Джаред', 'привет Джар', 'привет бот', 'прив Джаред', 'прив Джар', 'прив бот', 'дарова Джаред', 'дарова Джар', 'дарова бот') 

tell me how to do it.

    2 answers 2

     from itertools import product res = [f'{x} {y}' for x,y in product(BOT_HELLO, BOT_NAMES)] print(res) 

    result:

     ['привет Джаред', 'привет Джар', 'привет бот', 'прив Джаред', 'прив Джар', 'прив бот', 'дарова Джаред', 'дарова Джар', 'дарова бот'] 
    • Well, what about numpy? there seems to be faster? - Vasyl Kolomiets
    • @VasylKolomiets, when working with strings, it happens that a solution using Numpy loses in speed;) - MaxU
     [ i+" "+j for i in BOT_HELLO for j in BOT_NAMES ] ['привет Джаред', 'привет Джар', 'привет бот', 'прив Джаред', 'прив Джар', 'прив бот', 'дарова Джаред', 'дарова Джар', 'дарова бот']