I am having trouble understanding this bit of code, specifically its syntax.
a_list = [1,2,3,4,5,6]  
pi = lambda s: {s:a for s, a in enumerate(a_list)}[s]
I understand the lambda functions but what is [s] doing here?
I am having trouble understanding this bit of code, specifically its syntax.
a_list = [1,2,3,4,5,6]  
pi = lambda s: {s:a for s, a in enumerate(a_list)}[s]
I understand the lambda functions but what is [s] doing here?
 
    
    The [s] is a key to retrieve a value in the dict built in the lambda.
The s is 2 different vars with the same name, so maybe this way is more readable and it does exactly the same thing:
pi = lambda s: {key: val for key, val in enumerate(a_list)}[s]