riaz tabassum wrote:

> Sir  i have a problem to solve to python code. I have attached the pic of
> problem statement.

This is a text-only mailing list. Please describe the problem you are trying 
to solve in plain English. Thank you.

> code which i write is pasted here.
> "def Skew(Genome):
>     skew = {}
>     #initializing the dictionary
>     skew[0]=0#initializing the dictionary
> 
>     for i  in  range(len(Genome)):
>           if i==0:
> 
>               if Genome[i]=='G':
> 
>                   skew[i]=skew[i]+1
>               elif Genome[i]=='C':
> 
>                    skew[i]=skew[i]-1
>               else:
> 
>                   skew[i]=skew[i]
> 
> 
>           elif Genome[i]=='G':
> 
>                skew[i]=skew[i-1]+1
> 
> 
>           elif Genome[i]=='C':
>               skew[i]=skew[i-1]-1
> 
>           else:
>               skew[i]=skew[i-1]

Is the part above provided by your teacher? Then it's pobably correct and 
you can concentrate on

>     # your code here
>     return skew

Hint: the order of the items in a dict is undefined and you may even get 
different output when you run the same script twice.
As a simple way around this you can sort the keys and then create a list by 
looking up the corresponding values. 
Did you learn about list comprehensions? The sorted() function? Both may be 
useful.

> Genome="CGCAGATGTTTGCACGACTGTGACAC"
> print Skew(Genome).values()

That line should probably be 

print Skew(Genome)

as any data preprocessing is best done inside the Skew() function.
 
> #Sample Output:
> #0', '-1', '0', '-1', '-1', '0', '0', '0',
> #'1', '1', '1', '1', '2', '1', '1', '0', '1', '1',
> #'0', '0', '1', '1', '2', '2', '1', '1', '0'
> "
> 
> 
> But i am facing the problem that  i could not  include the first index
> which is initialized to zero in my answer.
> 
> 
> the error is shown as
> 
> Failed te #2.
> 
> Test Dataset:
> CGCAGATGTTTGCACGACTGTGACAC
> 
> Your output:
> ['-1', '0', '-1', '-1', '0', '0', '0', '1', '1', '1', '1', '2', '1',
> '1', '0', '1', '1', '0', '0', '1', '1', '2', '2', '1', '1', '0']
> 
> Correct output:
> 
> ['0', '-1', '0', '-1', '-1', '0', '0', '0', '1', '1', '1', '1', '2', '1',
> '1', '0', '1', '1', '0', '0', '1', '1', '2', '2', '1', '1', '0']
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to