Oct-09-2017, 03:15 AM
With such a small set of output values, the easiest approach is if-then-else statements:
Pseudocode:
if <s in range_1>:
return 1
elif <s in range_2>:
return 2
...
<s in range_1> could be implemented as one of these:
s in ('Alice',...,'Carol') # tuple
s in ['Alice',...,'Carol'] #list
If you had a much larger set of output values, it would be best to use a dict:
range_1 = {'Alice': 1,...,'Carol:1}
If you have both a reasonably large set of input and output values, you can just use a dict:
range = {'Alice':1,...,'Wanda':93}
Pseudocode:
if <s in range_1>:
return 1
elif <s in range_2>:
return 2
...
<s in range_1> could be implemented as one of these:
s in ('Alice',...,'Carol') # tuple
s in ['Alice',...,'Carol'] #list
If you had a much larger set of output values, it would be best to use a dict:
range_1 = {'Alice': 1,...,'Carol:1}
If you have both a reasonably large set of input and output values, you can just use a dict:
range = {'Alice':1,...,'Wanda':93}