Title: Nested For Loops Using List Comprehension
Slug: nested_for_loops_using_list_comprehension
Summary: Nested For Loops Using List Comprehension
Date: 2016-11-01 12:00
Category: Python
Tags: Basic
Authors: Chris Albon
In [2]:
# Create two lists
squads = ["1st Squad", '2nd Squad', '3rd Squad']
regiments = ["51st Regiment", '15th Regiment', '12th Regiment']
In [6]:
# Create a tuple for each regiment in regiments, for each squad in sqauds
[(regiment, squad) for regiment in regiments for squad in squads ]
Out[6]: