List

holger krekel pyth at devel.trillke.net
Sun Jun 2 16:05:45 EDT 2002


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





More information about the Python-list mailing list