Johan Geldenhuys wrote: > Thanks, Alan. > > That makes it a lot easier to understand. I'll play around with other > examples to see what it is doing. > > Johan >
A good first step to understanding a confusing lambda is to convert it to a normal function.\ Just my $.02, e. > -----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 > > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor