title: For loop and zip in python
body: <p>I have a code that I am trying to understand and I need help.</p>
  
  <pre><code>import numpy as np
  Class_numbers=np.array(['a','b','c'])
  students_per_class=np.array([10,20,30])
  print("Students counts per class:\n{}".format(
  {x: y for x, y in zip(Class_numbers, students_per_class)}))
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>Students counts per class:
  {'a': 10, 'b': 20, 'c': 30}
  </code></pre>
  
  <p>What I understand:
  1- we use {} and .format(...) to replace {} with ...</p>
  
  <p>Here are my questions:</p>
  
  <p>Q1- I do not understand "for x, y in zip(Class_numbers, students_per_class)". Is it like a 2d for loop? why we need the zip? Can we have 2d loop with out zip function?</p>
  
  <p>Q2-I am not understanding how x:y works! the compile understand automatically that the definition of x and y (in "x:y") is described in the rest of the line(e.g. for loop)?</p>
  
  <p>P.S: I am expert in MATLAB but I am new to python and it is sometimes very confusing!</p>
  
  <p>Ehsan</p>