I am trying to implement alternate to switch functionality in Python.
Example:
>>> def f(x):
return {
'report/1/client_1_2001.txt':'10.7.0.151 -> 10.7.0.152',
'report/1/client_1_3001.txt':'10.7.0.151 -> 10.7.0.153',
}.get(x,'No mapping')
>>> f('report/1/client_1_3001.txt')
'10.7.0.151 -> 10.7.0.153'
I have written a separate function which prints all the combinations
def msg():
for x in range(1,9):
for j in range(1,9):
if x == j:
continue
else:
print "'report/%s/client_%s_%s00%s.txt':'10.7.0.15%s -> 10.7.0.15%s'"%(x,x,j,x,x,j)
I am calling above function inside another function
def f(x):
return {msg()}.get(x,'No mapping')
When I am trying to access the value with this:
print f('report/2/client_2_1002.txt')
I see this error:
return {msg()}.get(x,'No mapping')
AttributeError: 'set' object has no attribute 'get'
Can someone let me know if I am missing anything here?


getto do there? You created a set. Sets don't provide any way to get specific items.'10.7.0.151 -> 10.7.0.153'when I executef('report/1/client_1_3001.txt')as shown in above "Example".msgto build a dict instead of print a bunch of stuff.