mercredi 24 mai 2017

if else simplification in python3.6 with multiple cases

I have a condition where user I have a[]. P is a file which has all the variables l, m, n .... which are populated.

then

if a[1]  = '1':
   p.l = a[2]
elif a[1] = '2':
   p.m = a[2]
elif a[1] = '3':
   p.n = a[2]

these conditions keep going till 20-25 of them

What is the best way to handle this in both python 3.6 and python 2.7

Aucun commentaire:

Enregistrer un commentaire