nested loops python code example
Example 1: dict comprehension python
# dict comprehension we use same logic, with a difference of key:value pair
# {key:value for i in list}
fruits = ["apple", "banana", "cherry"]
print({f: len(f) for f in fruits})
#output
{'apple': 5, 'banana': 6, 'cherry': 6}
Example 2: how to create a nested loop in python
for i in range(5):
for j in range(i):
# you can add many for loops or you can just write any code
Example 3: dict comprehension python
keys=['var1','var2','var3']
my_dict={key:np.zeros(10) for key in keys}