[Tutor] resizing an array of strings?

Karl Pflästerer sigurd at 12move.de
Mon Jun 6 18:03:39 CEST 2005


On  6 Jun 2005, jeffpeery at yahoo.com wrote:

>
> Hello, I'm having a bit of trouble resizing/reshaping an array of strings.
> 	here's what I'm trying to do:
>  
> myString = ['hi','my','name','is','Jeff']
> reshape(myString, (2,2))
>  
> What I get from this is something like:
>  
> [['h','i'],
> ['m','y']]
>  
> What I want is:
> [['hi','my'],
> ['name','is']]

If you explained exactly what you want (and showed what you tried to do)
it would be easier to help.  What does e.g. the tuple `(2,2)' mean?

Here's is an example which should give you an idea how to solve the
problem:

. >>> s = ['hi','my','name','is','Jeff']
. >>> s[0:2]
. ['hi', 'my']
. >>> s[2:4]
. ['name', 'is']
 
Your reshape function just has to create the list slices.


   Karl
-- 
Please do *not* send copies of replies to me.
I read the list


More information about the Tutor mailing list