Thanks, Alan. That makes it a lot easier to understand. I'll play around with other examples to see what it is doing.
Johan -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alan Gauld Sent: 22 February 2007 11:46 AM To: tutor@python.org Subject: Re: [Tutor] Explanation of this lambda "Johan Geldenhuys" <[EMAIL PROTECTED]> wrote > Would somebody care to explain what is happening in this process? > > def intToBin(self, x, count=8): > return "".join(map(lambda y:str((x>>y)&1), range(count-1, -1, > -1))) "".join() turns a list into a string map() returns a list where each item is the result of applying the lambda to the range() lamda y: ..... is a function to be applied str() converts to a string x>>y shifts the bits of x right by y places 010 -> 001 & 1 bitwise ands with 1 which returns 1 if the last bit is one. put the bits together and it should be clear. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.441 / Virus Database: 268.18.3/696 - Release Date: 2007/02/21 03:19 PM -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.441 / Virus Database: 268.18.3/696 - Release Date: 2007/02/21 03:19 PM _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor