[Tutor] Iterate over letters in a word
sanelson at gmail.com
Tue Mar 14 22:08:04 CET 2006
On 3/14/06, Steve Nelson <sanelson at gmail.com> wrote:
> On 3/14/06, Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
> > The idea is to unpack four single characters as a single 4-byte integer.
> That's really useful, thanks, as I was planning to iterate over each
> letter and call ord()
Ok, so experimenting a little further, and looking at the
documentation, it seems that len(string) and calcsize (i) must be the
same. Is there a reason why 'i' is a 4 byte integer? Doesn't this
mean that this method wouldn't scale if I then decided I wanted to
use, eg, a 6 byte key instead of a four? Or do I misunderstand?
I am also struggling to understand why a 4 byte integer is so large?
>>> mystring = "Hello I am Steve"
>>> import struct
>>> struct.unpack('i', mystring[0:4])
I can see that the largest number I can generate in a 1 byte integer
is 255 - which is (2^8)-1. Is the point that with a 4 byte number I
can actually get (2^32)-1 , ie 4294967295? This just seems like a
I suppose I've answered my question... but any comments or
clarifications would help a lot.
More information about the Tutor