Why is "while" ticking me off???

Alan Gauld alan.gauld at gssec.bt.co.uk
Wed Oct 11 06:16:15 EDT 2000


Huaiyu Zhu wrote:
> I quote an example here:
> 
> if val = dict1[key1]:
>         process1(val)
> elif val = dict2[key2]:
>         process2(val)
> elif val = dict3[key3]:
>         process3(val)
> ...

OR:

if dict1[key1]:
      process1(dictl[key1])
elif dict2[key2]:
      process2(dictl[key2])
elif dict3[key3]:
      process3(dictl[key2])
...
 
OK, There could be a performance overhead. In which case 
you have no alrternative to do 2 lines per branch.

> The entirely equivalent python code would require nested ifs
> 
> val = dict1[key1]
> if val:
>         process1(val)
> else:

Why use if/else if here when you used if/elif above? 
That just makes it look worse than it need be.

Alan g.
-- 
=================================================
This post represents the views of the author 
and does not necessarily accurately represent 
the views of BT.



More information about the Python-list mailing list