python - the calculation conditions IF in dictionaray -
i don't understand calculation condition if if dictionary :-
why when code
dlist = [{'bilbo':'ian','frodo':'elijah'} , {'bilbo':'martin','thorin':'richard'}] k = 'bilbo' [ ks[k] if k in ks else 'not present' ks in dlist] but when wrote code
[ ks[k] ks in dlist if k in ks else 'not present' ] i syntaxerror: invalid syntax
[ks[k] if k in ks else 'not present' ks in dlist] implies
[(ks[k] if k in ks else 'not present') ks in dlist] your proposal of
[ ks[k] ks in dlist if k in ks else 'not present' ] cannot have parentheses placed implicitly in sensible way. here various ways of grouping syntax. none of them intended:
[(ks[k] ks in dlist) if k in ks else 'not present'] [ks[k] ks in (dlist if k in ks else 'not present')] [ks[k] ks in dlist if k in ks]
Comments
Post a Comment