advanced for loop in python code example
Example 1: how to create a break in iterating a sequence with a specific set of values in python
>>> d = {'foo': 1, 'bar': 2, 'baz': 3}
>>> for k, v in d.items():
... print('k =', k, ', v =', v)
...
k = foo , v = 1
k = bar , v = 2
k = baz , v = 3
Example 2: iterating over the two ranges simultaneously and saving it in database
from .models import userData as us
import pandas as pd
def enterData(request):
data=pd.read_csv(r"abc.csv",encoding='ISO-8859-1')
username=data['userName']
address=data['address']
for a, b in zip(username, address):
db=ud(userName=a,Address=a)
db.save()