Hi Kumar, 

I've been studiously avoiding re, and I think you can too for this problem - 

>I want to remove Name=Xxxx_at identifiers.

>My List:
>['Name=32972_at',
>'Cell1=432\t118\tN\tcontrol\t32972_at\t0\t13\tA\tA\tA\t0\t75952\t-1\t-1\t99\t',
>'Cell2=432\t117\tN\tcontrol\t32972_at\t0\t13\tA\tT\tA\t0\t75312\t-1\t-1\t99\t',
>'Cell3=499\t632\tN\tcontrol\t32972_at\t1\t13\tC\tC\tC\t1\t404979\t-1\t-1\t99\t']


so - 
hasName=[]
for indexNum in range(len(myList):
       if "Name=" in myList[indexNum]:
                hasName.append(indexNum)

hasName.reverse()

for element in hasName:
     del myList(element)

Might be able to do it 

hasName=[]
for indexNum in myList.index(): #???
       if "Name=" in indexNum:
                hasName.append(indexNum)

hasName.reverse()

for element in hasName:
     del myList(element)

But, you need a list of the index numbers of the list members to be
deleted, and then you need to reverse it... why?

aList=['b','c','d']
indexes=[0,1,2]
for element in indexes:
    del aList[element]

Watch what happens as it runs.

element=0
del aList[0]
aList=['c','d']

element = 1
del aList[1]
aList=['c']

element = 2
del aList[2]

IndexError - value out of range.

Whereas - 

aList=['b','c','d']
indexes=[0,1,2]
indexes.reverse()

for element in indexes:
    del aList[element]

element=2
del aList[2]
aList=['b','c']

element = 1
del aList[1]
aList=['b']

element=0
del aList[0]
aList=[]


HTH

Liam Clarke
On Tue, 7 Dec 2004 14:09:32 -0800 (PST), kumar s <[EMAIL PROTECTED]> wrote:
> Hello group,
>  Thank you very much for your kind replies. In fact I
> survived to pull out what I needed by going with
> Kent's tip by enumerating on iterator.
> 
> The problem with me is suddenly I embarked on
> something big problem and I am surviving it in pieces
> by writing pieces of code.
> 
> I have another question:
> To be brief:
> 
> My list contains some elements that I do not want and
> I want to remove unwanted elements in my list:
> 
> My TEXT file looks like this:
> 
> Name=32972_at
> Cell1=xxx       xxx     N       control 32972_at
> Cell1=xxx       xxx     N       control 32972_at
> Cell1=xxx       xxx     N       control 32972_at
> Cell1=xxx       xxx     N       control 32972_at
> Name=3456_at
> Cell1=xxx       xxx     N       control 3456_at
> Cell1=xxx       xxx     N       control 3456_at
> Cell1=xxx       xxx     N       control 3456_at
> Cell1=xxx       xxx     N       control 3456_at
> .........       ...     x       xxxxxxxxxxxxxxx
> (34K lines)
> 
> I want to remove Name=Xxxx_at identifiers.
> 
> My List:
> ['Name=32972_at',
> 'Cell1=432\t118\tN\tcontrol\t32972_at\t0\t13\tA\tA\tA\t0\t75952\t-1\t-1\t99\t',
> 'Cell2=432\t117\tN\tcontrol\t32972_at\t0\t13\tA\tT\tA\t0\t75312\t-1\t-1\t99\t',
> 'Cell3=499\t632\tN\tcontrol\t32972_at\t1\t13\tC\tC\tC\t1\t404979\t-1\t-1\t99\t']
> 
> I tried to resolve in this way:
> 
> >>>pat = re.compile('Name')
> >>> for i in range(len(cord)):
>         x = pat.search(cord[i])
>         cord.remove(x)
> 
> I know I am wrong here because I do not know how to
> search and remove an element in a list. Can any one
> please help me.
> 
> on Page 98, chapter Lists and dictionaries of mark
> lutz's learning python. It is mentioned in table 6-1 :
> L2.append(4)  Methods: grow,sort,search,reverse etc.
> 
> Although not much is covered on this aspect in this
> book, I failed to do more operations on list.
> 
> Looking forward for help from tutors.
> 
> Thank you.
> Kumar.
> 
> 
> 
> 
> --- Kent Johnson <[EMAIL PROTECTED]> wrote:
> 
> > kumar,
> >
> > Looking at the quantity and structure of your data I
> > think the search you are doing is going to be
> > pretty slow - you will be doing 4504 * 398169 =
> > 1,793,353,176 string searches.
> >
> > Where does the seq data come from? Could you
> > consolidate the pairs of lines into a single record?
> > If
> > you do that and extract the '399:559' portion, you
> > could build a dict that maps '399:559' to the
> > full record. Looking up '399:559' in the dictionary
> > would be much, much faster than searching the
> > entire list.
> >
> > If you have multiple entries for '399:559' you could
> > have the dict map to a list.
> >
> > Kent
> >
> > kumar s wrote:
> > >
> > >>>>len(x)
> > >
> > > 4504
> > >
> > >>>>x[1:10]
> > >
> > > ['454:494', '319:607', '319:608', '322:289',
> > > '322:290', '183:330', '183:329', '364:95',
> > '364:96']
> > >
> > >>>>len(seq)
> > >
> > > 398169
> > >
> > >>>>seq[0:4]
> > >
> > > ['>probe:HG-U95Av2:1000_at:399:559;
> > > Interrogation_Position=1367; Antisense;',
> > > 'TCTCCTTTGCTGAGGCCTCCAGCTT',
> > > '>probe:HG-U95Av2:1000_at:544:185;
> > > Interrogation_Position=1379; Antisense;',
> > > 'AGGCCTCCAGCTTCAGGCAGGCCAA']
> > >
> > >
> > >
> > >>>>for ele1 in x:
> > >
> > >     for ele2 in seq:
> > >             if ele1 in ele2:
> > >                     print ele2
> > >
> > >
> > >
> > >>probe:HG-U95Av2:31358_at:454:493;
> > >
> > > Interrogation_Position=132; Antisense;
> > >
> > >>probe:HG-U95Av2:31358_at:319:607;
> > >
> > > Interrogation_Position=144; Antisense;
> > >
> > >
> > >
> > >
> > >
> > >
> > > How Do I WANT:
> > >
> > > I want to print get an output like this:
> > >
> > >
> > >
> > >>probe:HG-U95Av2:1000_at:399:559;
> > >
> > > Interrogation_Position=1367; Antisense;'
> > > TCTCCTTTGCTGAGGCCTCCAGCTT
> > >
> > >
> > >>probe:HG-U95Av2:1000_at:544:185;
> > >
> > > Interrogation_Position=1379; Antisense;
> > > AGGCCTCCAGCTTCAGGCAGGCCAA
> > >
> > >
> > > can any one please suggest what is going wrong in
> > my
> > > statements and how can I get it.
> > >
> > > Thank you.
> > > Kumar
> > >
> > >
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > Yahoo! Mail - 250MB free storage. Do more. Manage
> > less.
> > > http://info.mail.yahoo.com/mail_250
> > > _______________________________________________
> > > Tutor maillist  -  [EMAIL PROTECTED]
> > > http://mail.python.org/mailman/listinfo/tutor
> > >
> > _______________________________________________
> > Tutor maillist  -  [EMAIL PROTECTED]
> > http://mail.python.org/mailman/listinfo/tutor
> >
> 
> __________________________________
> Do you Yahoo!? 
> Yahoo! Mail - now with 250MB free storage. Learn more.
> 
> 
> http://info.mail.yahoo.com/mail_250
> _______________________________________________
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
_______________________________________________
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to