0

Come from the Ruby world, Python for me is a little “stange”. Someone's code:

the_dict = {"a": 1, "b":2}
another_dict = {
    key: val 
    for key, val in the_dict.iteritems()
}
print(another_dict)

returns:

{'a': 1, 'b': 2}

The for .. in loop is postpostion. However I can not find any Python doc about this, can anyone give some explanation on this?

PS: Glad to see something familiar in Python cause in Ruby we often do " a = somthing if codition.valid?"

chailong
  • 286
  • 3
  • 11

0 Answers0