int to str in list elements..

John Machin sjmachin at lexicon.net
Tue Oct 16 10:29:23 CEST 2007


Marc 'BlackJack' Rintsch wrote:
> On Tue, 16 Oct 2007 06:18:51 +0000, Tim Roberts wrote:
>
> > John Machin <sjmachin at lexicon.net> wrote:
> >>On Oct 15, 4:02 am, Abandoned <best... at gmail.com> wrote:
> >>> Hi..
> >>> I have a list as a=[1, 2, 3 .... ] (4 million elements)
> >>> and
> >>> b=",".join(a)
> >>> than
> >>> TypeError: sequence item 0: expected string, int found
> >>> I want to change list to  a=['1','2','3'] but i don't want to use FOR
> >>> because my list very very big.
> >>
> >>What is your worry: memory or time? The result string will be very
> >>very very big.
> >
> > It's an interesting mental exercise to try to figure out just how large
> > that string will be, without using Python.
> >
> > I get 30,888,889 bytes...
>
> I think you have an off by one error here.  (One number, not one byte)  :-)

It's certainly off :

[Best viewed in a fixed-width font ... umm, do they still sell squared
paper for doing arithmetic on? I had to rip a page out of a notebook
and rotate it through 90 degrees]
3000001 x 8 = 24000008
0900000 x 7 = 06300000
0090000 x 6 = 00540000
0009000 x 5 = 00045000
0000900 x 4 = 00003600
0000090 x 3 = 00000270
0000009 x 2 = 00000018
-------       --------
4000000       30888896
less one for a comma counted above but not used -> 30888895
difference is 6 bytes which is one number (8) LESS 2 bytes

Cheers,
John




More information about the Python-list mailing list