python - PEP 8 warning "Do not use a lambda expression use a def" for a defaultdict lambda expression -


i using below python code create dictionary.but getting 1 pep 8 warning dct_structure variable. warning is: do not use lambda expression use def

from collections import defaultdict  dct_structure = lambda: defaultdict(dct_structure) dct = dct_structure() dct['protocol']['tcp'] = 'reliable' dct['protocol']['udp'] = 'unreliable' 

i not comfortable python lambda expression yet. can me define function below 2 line of python code avoid pep warning.

dct_structure = lambda: defaultdict(dct_structure) dct = dct_structure() 

a lambda in python anonymous function awkward restricted syntax; warning saying that, given assigning straight variable - giving lambda name -, use def, has clearer syntax , bakes function name in function object, gives better diagnostics.

you may rewrite snippet as

def dct_structure():     return defaultdict(dct_structure)   dct = dct_structure()  

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -