I want to make a program that cross checks strings.

Here is an example :

Enter line: AAGGAA
This sequence can make a hairpin

Enter line: UGAG
This sequence cannot make a hairpin

Enter line: GUGCCACGGCACCGUG
This sequence can make a hairpin

Enter line: GUACCACGGCACCGUG
This sequence cannot make a hairpin

My challenge states

Your task is to write a program which reads in a sequence of RNA and determines whether or not it could, if folded in the middle, form a hairpin structure. All sequences that we use to test your program will be of even length.

Basically it splits strings which are even and cross checks those strings if they can make a hairpin sequence.

so if the string AAGGAA was entered,
it would be split into AAG and GAA and the first letter of string one has to match the last letter of string two, and so on.

Can someone please help me?
I've tried coding it but have had no luck :(

Recommended Answers

All 4 Replies

split the RNA sequence at the midline and reverse the second part then compare the 2parts.
something like a function that takes the sequence and returns the following:

return sequence[:len(sequence)/2]==sequence[len(sequence)/2:][::-1]

It's called palindrome and easiest is to just comparenstrimg with reversed string. But your example GUA....GUG is not one!

something like this maybe:

def hairpin(seq):
    print seq==seq[::-1]

hairpin(raw_input("Enter RNA Sequence: "))

Thanks guys! It passed :D
The function I used was
return sequence[:len(sequence)/2]==sequence[len(sequence)/2:][::-1]

Thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.