How To Create Cartesian Products in Python - Subscriber Requests Series


How To Create Cartesian Products in Python - Subscriber Requests Series

*

Full Code From This Example:


YouTube Description:

Brief tutorial video on how we can use python to create cartesian products from multiple variables. We'll use itertools to do this and the product() function. Thanks so much for all the support!! We broke 3k subscribers - You all are incredible. Thank you so much for the continued support :) Drop me a request of your own if you have one! I'm happy to help in any way I can. ***************************************************************** Full code from the video: import itertools list1 = ['a','b','c'] list2 = [1,2,3] list3 = [] for l in list1: for b in list2: list3.append(l + str(b)) print(list3) # more than two series and want true tuples coffee = ['Latte','Cappuccino','Filter'] flavor = ['Hazelnut','Vanilla','Mocha'] milk = ['no milk','skim','2%'] for element in itertools.product(coffee, flavor, milk): print(element) https://github.com/Derrick-Sherrill/DerrickSherrill.com/blob/master/cp_ex.py Additional Use of itertools can be found on my website: https://www.coffeepoweredcoder.com/tutorials/requests/cartesian-products/ ***************************************************************** Code from this tutorial and all my others can be found on my GitHub: https://github.com/Derrick-Sherrill/DerrickSherrill.com Check out my website: https://www.derricksherrill.com/ If you liked the video - please hit the like button. It means more than you know. Thanks for watching and thank you for all your support!! Always looking for suggestions on what video to make next -- leave me a comment with your project! Happy Coding!

Enjoy this content? Consider Subbing to the Youtube channel





Derrick Sherrill

By: Derrick Sherrill

Thanks for visiting my page! I'm working hard to make the best content I can for you. I love watching people learn and teaching others. Happy Coding!

Become a Patreon!