+ 1

What is meaning of this- a= { 0:1,1:2} _sum =0 for b in a : _sum+=b

17th Feb 2019, 11:16 AM
Nikhil Tale
Nikhil Tale - avatar
2 Réponses
+ 6
This is a a quiz question IIRC. Here the "b"s are the keys if the dictionary. This code essentially finds the sum of the keys.
17th Feb 2019, 12:49 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
a is a dictionary where 0 is mapped to 1 and 1 is mapped to 2 for b in a iterates through all keys (0,1) The loop counts their sum
17th Feb 2019, 11:36 AM
michal