List

Gold Fish occeanlinux at linuxmail.org
Sun Jun 2 22:56:10 CEST 2002


----- Original Message -----
From: holger krekel <pyth at devel.trillke.net>
Date: Sun, 2 Jun 2002 22:05:45 +0200
To: Gold Fish <occeanlinux at linuxmail.org>
Subject: Re: List


> Gold Fish wrote:
> > Charl P. Botha wrote:
> > 
> > > In article <3cfa6ed8_1 at news.iprimus.com.au>, Gold Fish wrote:
> > >> Assume we got 2 list
> > >> list 1 = ['ABC','CDG','DAV','FE','FECA','FEAFA','FEA']
> > >> list 2 = []
> > >> how can we copy element from list 1 to list 2 say i just want to copy the
> > >> 3 element 'CDG','DAV','FE' to list2 only.
> > > 
> > > list1 = ['ABC','CDG','DAV','FE','FECA','FEAFA','FEA']
> > > list2 = list1[1:4]
> > > 
> > > Is that what you meant?
> > > 
> > No i mean if i got from list1 i wanna take 3 elements in any position to 
> > list2 but i don't know how many item in that list.
> 
> if you have a starting index 'i' then you can do
> 
>   list1[i:i+3]  
> 
> which returns you at most 3 elements, starting from position 'i'.
> 
> If this is still not what you want, then please give 
> two or three examples of what you want to achieve.
> 
>     holger
> 

What i would achieved is that I got the list of elements say that 10 elements in the list, i want to seperate this list into 2,or 3 sublists depends on user input the number. Then these subject contain the number of elements say 2, or 3 depend on user define. How can i do this. For example. 
BigList = [e1,e2,e3,e4,e5,e6,e7]
this will be divided into 4 small sublists which is sublist1,sublist2,sublist3,sublist4.These sublists will have maximum of 2 elements inside therefore, sublist1 = [e1,e2], sublist2=[e3,e4],sublist3=[e5,e6] and sublist7=[e7]
I would appreciate that you could help me this problem. I spend so much time to think about it but it's look like i stuck in the maze when trying to divide biglist into small list and small list to nano list. 
 

-- 
Get your free email from www.linuxmail.org 


Powered by Outblaze





More information about the Python-list mailing list