[Python-ideas] Where-statement (Proposal for function expressions)
Jan Kaliszewski
zuo at chopin.edu.pl
Sat Jul 18 14:29:26 CEST 2009
Stephen J. Turnbull <stephen at xemacs.org> wrote:
> Problem is, *that only works for very flat
> semantics*, in fact only for a root node and one generation of
> descendents (and not very many of them, with none very complex,
> at that).
Agree that where clause is good for short and rather flat structures.
The same thing is with list-comprehensions/generator expressions --
probably it is not a good idea to use them like that:
(
2*item for item in (seq4
for seq4 in sorted(seq3
for seq3 in set(seq2
for seq2 in filter(None, reversed(seq1
for seq1 in sorted(seq0
for seq0 in map(lambda x, y: y(x),
adict0.keys(),
adict0.values()
)
if set(seq0) > set(adict0.values()))
if len(seq1) > 3))
)
if seq3.issubset(adict3.items()))
if seq4)
)
:)
Me wrote:
> IMHO 'where' would be better than lambda in many contexts, especially
> if there is a need for function as argument, e.g. for filter(), map(),
> sort(key=...) etc., and also for some list comprehensions and generator
> expressions.
Of course, 'where' is not a statement/multi-line lambda, but in practice
it'd be take role of it, being IMHO really useful.
Still I'd prefer:
a = sorted(b, key=how) where def how(item): # or even 'using'
DO SOMETHING # instead of 'where def'
return key
...rather than:
def how(item):
DO SOMETHING
return key
a = sorted(b, key=how)
Mainly, not because I need it visually but because in such situations
(say 'lambda-situations') I'm not interested *how to do* until I think
about *what to do*.
Regards,
--
Jan Kaliszewski <zuo at chopin.edu.pl>
More information about the Python-ideas
mailing list