/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// add a function as an element of a dictionary >>> {1: lambda: len('ciao')} >>> {1: <function <lambda> at 0x101d530>} // get element with specified key >>> {1: lambda: len('ciao')}[1] >>> <function <lambda> at 0x101d5f0> >>> a = {1: lambda: len('ciao')}[1] >>> a >>> <function <lambda> at 0x101d670> // run the function-element >>> a() >>> 4 // or run it directly from here! >>> {1: lambda: len('ciao')}[1]() >>> 4