₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,392 members, 8,421,704 topics. Date: Saturday, 06 June 2026 at 09:10 PM

Toggle theme

Python: I Need Help With A Problem - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPython: I Need Help With A Problem (1407 Views)

1 Reply (Go Down)

Python: I Need Help With A Problem by peacettw(op): 8:45pm On Jan 09, 2021
Ok. So I am currently going through an online course on DNA base pairing.

I decided to use python to help with the pairing. Essentially "A" should pair with "T" and "G" should pair with "C" and vise versa.

At the end of it all, I want a sequence of AAATTTGGGCCC to become TTT, AAA, CCC, GGG.

My issue is how to arrive at "TTT , AAA , CCC, GGG" as one string with python

Please look at the code below and let me know where I am getting it wrong. Thanks

dna=
"CCTGTATGCCCAAGGGGTTTCGATCGTAC
GACTGTCAGTCAGCTAGCT"

count =0
for i in dna:
count=count +1
print(i, end="" )
if count % 3 ==0:
print(", ", end="" )

The end result is not a single string, rather it's broken up... I can put them all together in a list with the append method but I just want a string and not a list.

PS: please ignore the lack of indentations where appropriate, for some reason this social platform is stripping all left spaces
Re: Python: I Need Help With A Problem by peacettw(op): 9:03pm On Jan 09, 2021
Is noone here?
Re: Python: I Need Help With A Problem by peacettw(op): 9:51pm On Jan 09, 2021
Never mind, I have figured it out

dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"

l=list()
n= len(dna)/3
count=0

print(dna, "\n" )
while n>0:
j=dna[count:count+3]
count = count + 3
n= n - 1
l.append(j)
print(j)
print(l)
Re: Python: I Need Help With A Problem by ibromodzi: 7:29pm On Jan 10, 2021
peacettw:
Never mind, I have figured it out

dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"

l=list()
n= len(dna)/3
count=0

print(dna, "\n" )
while n>0:
j=dna[count:count+3]
count = count + 3
n= n - 1
l.append(j)
print(j)
print(l)
Use the code formatting tool next time you are seeking for help, it is not easy reading codes like a normal text. Computational Molecular Biology is an interesting domain by the way. Keep exploring bro.
Re: Python: I Need Help With A Problem by peacettw(op): 8:28pm On Jan 10, 2021
ibromodzi:
Use the code formatting tool next time you are seeking for help, it is not easy reading codes like a normal text. Computational Molecular Biology is an interesting domain by the way. Keep exploring bro.
Ok. Thanks for the tips and I am female.. May I know where to access the code formatting tool?
Re: Python: I Need Help With A Problem by ibromodzi: 8:42pm On Jan 10, 2021
peacettw:
Ok. Thanks for the tips and I am female.. May I know where to access the code formatting tool?
Oh, sorry about that. Just click on the hash logo and insert your code there.

Re: Python: I Need Help With A Problem by peacettw(op): 10:23pm On Jan 10, 2021
ibromodzi:
Oh, sorry about that. Just click on the hash logo and insert your code there.
Thanks a lot
Re: Python: I Need Help With A Problem by ecomm(m):
.
Re: Python: I Need Help With A Problem by zizytd(m):
peacettw:
Never mind, I have figured it out

dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"

l=list()
n= len(dna)/3
count=0

print(dna, "\n" )
while n>0:
j=dna[count:count+3]
count = count + 3
n= n - 1
l.append(j)
print(j)
print(l)
Look at the attached image after the print list(l), is it what you want?

you can also do it using for loop. it is shorter, see second attachment.

Re: Python: I Need Help With A Problem by peacettw(op):
zizytd:
Look at the attached image after the print list(l), is it what you want?

you can also do it using for loop. it is shorter, see second attachment.
Perfect. Thanks a whole lot. Seems that I have so much to learn.

Is there like a community of python coders in Nigeria that I can join?
Re: Python: I Need Help With A Problem by Starkid3010(m): 6:18am On Jan 11, 2021
peacettw:
Never mind, I have figured it out

dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"

l=list()
n= len(dna)/3
count=0

print(dna, "\n" )
while n>0:
j=dna[count:count+3]
count = count + 3
n= n - 1
l.append(j)
print(j)
print(l)
you can actually use another method for this... I am not familiar with this your method very well
Re: Python: I Need Help With A Problem by peacettw(op): 6:57am On Jan 11, 2021
ecomm:
tongue

rand_dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"

dna = {'C': [], 'T': [], 'A': []}

for letter in rand_dna:
if letter == 'C':
dna['C'].append('C')
Just seeing this. Not quite what I wanted but thanks a lot for the effort.
Re: Python: I Need Help With A Problem by peacettw(op): 7:05am On Jan 11, 2021
Starkid3010:
you can actually use another method for this... I am not familiar with this your method very well
I understand. It can be quite tricky.. Take for instance my challenge. All I wanted was how to convert the contents of a list back to a string. Never knew that a string had a join() method until now.

Need to study more
Re: Python: I Need Help With A Problem by peacettw(op): 7:07am On Jan 11, 2021
Starkid3010:
you can actually use another method for this... I am not familiar with this your method very well
Oh. That's splendid. Can you tell us which other way this can also be addressed?
Re: Python: I Need Help With A Problem by zizytd(m): 8:12am On Jan 11, 2021
peacettw:
Perfect. Thanks a whole lot. Seems that I have so much to learn.

Is there like a community of python coders in Nigeria that I can join?
The more you practice the better you become. I don't have any idea about any community of python coders in Nigeria.
Re: Python: I Need Help With A Problem by Starkid3010(m): 9:54am On Jan 11, 2021
peacettw:
I understand. It can be quite tricky.. Take for instance my challenge. All I wanted was how to convert the contents of a list back to a string. Never knew that a string had a join() method until now.

Need to study more
yeah that's where I am driving at
Just ' '.join() will do it easily
I just started programming also
Re: Python: I Need Help With A Problem by Abcruz(m): 10:51pm On Jan 11, 2021
peacettw:
Oh. That's splendid. Can you tell us which other way this can also be addressed?
I used the BioPython package for DNA analysis and everything is simplified with it.
With BioPython, transcription and translation takes less than a line of code. You can install and learn it as well.
Re: Python: I Need Help With A Problem by peacettw(op): 3:19am On Jan 12, 2021
Abcruz:
I used the BioPython package for DNA analysis and everything is simplified with it.
With BioPython, transcription and translation takes less than a line of code. You can install and learn it as well.
Thanks a whole lot
Re: Python: I Need Help With A Problem by Abcruz(m): 8:32am On Jan 12, 2021
peacettw:
Thanks a whole lot
You're welcome.
Re: Python: I Need Help With A Problem by trippleXXL(m): 12:02pm On Jan 12, 2021
Please can you recommend anywhere on Lagos Mainland where one can learn coding from beginner level.
Re: Python: I Need Help With A Problem by Stellar360(m): 9:09am On Jan 14, 2021
peacettw:
Never mind, I have figured it out
dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"
l=list() n= len(dna)/3 count=0
print(dna, "\n" ) while n>0: j=dna[count:count+3] count = count + 3 n= n - 1 l.append(j) print(j) print(l)
this is great, dear. guess i really have to return to python soon as possible.
Re: Python: I Need Help With A Problem by Stellar360(m): 9:10am On Jan 14, 2021
ecomm:
tongue
rand_dna = "CCTGTATGCCCAAGGGGTTTCGATCGTACGACTGTCAGTCAGCTAGCT"
dna = {'C': [], 'T': [], 'A': []}
for letter in rand_dna: if letter == 'C': dna['C'].append('C')
wow! and this right here, is the beauty of coding with Python
1 Reply

Developers For Hire.. We Are A Problem Solving Team.. Try UsHelp With A Problem Of Building A Network Intrusion detection system234

Where Can One Learn Ethical Hacking In NsukkaReact + Css Vs React + Tailwindcss Which Do You Prefer??Javafx For Gui Developer