1. 9
  1.  

  2. 4

    I wonder if you could keep memory from exhausting by using a set comprehension with a single value..

    {1 for nonsense in map(lambda c:
          c[0].sendall(c[0].recv(1024)) and c[0].close(),
          (s.accept() for _ in itertools.count(1)))}
    
    1. 1

      Ooooh! That’s a fancy, fancy idea. Can make it shorter by just doing set(map(lambda c: ... ))

      1. 3

        Or (untested):

        {cs.sendall(cs.recv(1024)) and cs.close()
         for _ in itertools.count()
         for cs,addr in [s.accept()]}
        

        I’ve been known to use the ... for foo in [bar] construction in real code occasionally.

    2. 3

      I’ve seen one line Python programs before that implented things like Lisp interpreters or any other number of crazy things, but never tried to understand what was going on because the code is so damn ugly. When it occurred to me today that local bindings could be done like this, it truly unlocked the mystery of how more complicated things could be accomplished.

      1. 1

        Python gets “Javascript modules”!