Strings and Lists
Bill Mill
bill.mill at gmail.com
Mon Apr 18 09:42:32 EDT 2005
On 18 Apr 2005 04:42:17 -0700, Tom Longridge <tomlongridge at gmail.com> wrote:
> My current Python project involves lots repeatating code blocks,
> mainly centred around a binary string of data. It's a genetic
> algorithm in which there are lots of strings (the chromosomes) which
> get mixed, mutated and compared a lot.
>
> Given Python's great list processing abilities and the relative
> inefficiencies some string operations, I was considering using a list
> of True and False values rather than a binary string.
>
> I somehow doubt there would be a clear-cut answer to this, but from
> this description, does anyone have any reason to think that one way
> would be much more efficient than the other? (I realise the best way
> would be to do both and `timeit` to see which is faster, but it's a
> sizeable program and if anybody considers it a no-brainer I'd much
> rather know now!)
>
> Any advice would be gladly recieved.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Tom,
it seems to me that, if efficiency is your main goal, you should store
your data as a list of integers, and use the bit-twiddling operators
to get at your data. These should be *very* fast, as well as memory
efficient.
Peace
Bill Mill
bill.mill at gmail.com
More information about the Python-list
mailing list