[Tutor] resizing an array of strings?

Pujo Aji ajikoe at gmail.com
Mon Jun 6 17:57:53 CEST 2005


Try this code:

def myfuncSplit(row,col,myList):
  RBig = []
  cou=-1
  for i in range(row):
    RSmall= []
    for j in range(col):
      cou+=1
      RSmall.append(myList[cou])
    RBig.append(RSmall[:])
  
  return RBig
  

if __name__== '__main__':
  myString = ['hi','my','name','is','Jeff']
  result = myfuncSplit(2,2,myString)
  print result


On 6/6/05, Jeff Peery <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']] 
>   
> How might this work best? 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
>


More information about the Tutor mailing list