[Tutor] looping problem

jim stockford jim at well.com
Sat Sep 23 20:39:35 CEST 2006


#!/usr/bin/python
# or whatever is the absolute path to python on your system

counter = 0
for  i  in "a","b","c","d","e","f","g" :
	if counter%3 == 0 :
		print i + " list one ", counter, counter%3
	if counter%3 == 1 :
		print i + " list two ", counter, counter%3
	if counter%3 == 2 :
		print i + " not used ", counter, counter%3
print "done"


On Sep 23, 2006, at 9:03 AM, kumar s wrote:

> hi,
>
> thank you. this is not a homework question.
>
> I have a very huge file of fasta sequence.
>
>> GeneName xxxxxxxx \t yyyyyyyy
> AATTAAGGAAAAAA..........
>
> (1000 lines)
> AATAAGGA
>> GeneName xxxxxxxx \t yyyyyyyy
> GGAGAGAGATTAAGAA
> (15000 lines)
>
> when I read this as:
>
> f2= open('myfile','r')
> dat = f2.read().split('\n')
>
> turned out to be very expensive deal on computer.
>
> Instead I tried this:
>
> dat = f2.read()
>
> (reading into jumbo file of 19,100,442,1342 lines is
> easy but getting into what i want is a problem).
>
> I want to create a dictionary where 'GeneName' as key
> and sequence of ATGC characters as value
>
> biglist = dat.split('\t')
> ['GeneName xxxxxxxx','yyyyyyyy','ATTAAGGCCAA'.......]
>
> Now I want to select ''GeneName xxxxxxxx' into listA
> and 'ATTAAGGCCAA' into listB
>
> so I want to select 0,3,6,9 elements into listA
> and 2,5,8,11 and so on elements into listB
>
> then I can do dict(zip(listA,listB))
>
> however, the very loops concept is getting blanked out
> in my brain when I want to do this:
>
> for j in range(len(biglist)):
>         from here .. I cannot think anything..
>
> may be it is just mental block.. thats the reason I
> seek help on forum.
>
> Thanks
>
>
> --- jim stockford <jim at well.com> wrote:
>
>> keep a counter in your loop. is this a homework
>> question?
>>
>> On Sep 23, 2006, at 8:34 AM, kumar s wrote:
>>
>>> hi,
>>>
>>> the reason could be that I did not quite
>> understand
>>> the concept of looping
>>>
>>> I have a list of 48 elements
>>>
>>> I want to create another two lists , listA and
>> listB
>>>
>>> I want to loop through the list with 48 elements
>> and
>>>
>>> select element with index 0,3,6,9,12 ..etc into
>> listA
>>>
>>> select elements with index 2,5,8,11 etc into
>> listB.
>>>
>>>
>>> Could any one help me how can I do that
>>>
>>> thankyou
>>>
>>> __________________________________________________
>>> Do You Yahoo!?
>>> Tired of spam?  Yahoo! Mail has the best spam
>> protection around
>>> http://mail.yahoo.com
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>



More information about the Tutor mailing list