Re: [Tutor] Pythonify this code!

2009-07-14 Thread A.T.Hofkamp
Dave Angel wrote: def separateToList(num): """ changes an integer 0-255 into a list of ints, size exactly 3 """ return map(int, list(format(num, "03d"))) Nice! Note that the "list" conversion is not needed; when you iterate over a string you automatically get each character in

Re: [Tutor] Pythonify this code!

2009-07-14 Thread Dave Angel
A.T.Hofkamp wrote: Muhammad Ali wrote: def separateToList(num): """ changes an integer into a list with 0's padded to the left if the number is in tens or units """ assert(num <= 255) s = str(num) li = [] if len(s) > 2: li = [s[0:1], s[1:2], s[2:3]]

Re: [Tutor] Pythonify this code!

2009-07-14 Thread A.T.Hofkamp
Muhammad Ali wrote: def separateToList(num): """ changes an integer into a list with 0's padded to the left if the number is in tens or units """ assert(num <= 255) s = str(num) li = [] if len(s) > 2: li = [s[0:1], s[1:2], s[2:3]] elif len(s) > 1:

Re: [Tutor] Pythonify this code!

2009-07-14 Thread Muhammad Ali
Hi everyone, Thanks for the comments Dave and Alan! Based on these I have updated the code... I don't know if this is more readable. @Dave: I kept the original separate and combine function with bases as I thought I would move them to a math library if I need to work in other bases, however now

Re: [Tutor] Pythonify this code!

2009-07-13 Thread ALAN GAULD
Steganography's really neat! You should look into it. > > I did a quick lookup on Wikipedia. > Basically what his code does is takes an image, and it twiddles the least significant bits > > Interestingly when I was at university the head of signal processing was into crypto stuff and was look

Re: [Tutor] Pythonify this code!

2009-07-13 Thread Dave Angel
Muhammad Ali wrote: Hi, This is my first attempt at python. I tried my hand at steganography for fun. The code includes separate, combine, encode, decode functions. The separate function takes a number and it's base and returns a list containing each digit of the number in a list, vice versa for

Re: [Tutor] Pythonify this code!

2009-07-13 Thread Luke Paireepinart
> > > > I tried my hand at steganography >> > > Never heard of it before![snip] > > I didn't notice anything that would be v3 specific. Also I can't > comment on the algorithm since I don't really know what its > doing! > Alan, Steganography's really neat! You should look into it. Basically wha

Re: [Tutor] Pythonify this code!

2009-07-13 Thread Alan Gauld
"Muhammad Ali" wrote I tried my hand at steganography Never heard of it before! #The code starts here: def separate(num, base): li = [] while num / base > 0: li.insert(0, num % base) num = num / base li.insert(0,num) return li def combine(tup, base): num = 0

[Tutor] Pythonify this code!

2009-07-13 Thread Muhammad Ali
Hi, This is my first attempt at python. I tried my hand at steganography for fun. The code includes separate, combine, encode, decode functions. The separate function takes a number and it's base and returns a list containing each digit of the number in a list, vice versa for combine. The encode f