Wondering why when I write return arg after the for loop, I get the whole list I put in, but when I return reverse, only the last value in the list I provide prints
def reverse_complement(**seqs):
for arg in seqs.values():
reverse=arg[::-1]
return reverse
print(reverse_complement(a='CGTC', b='ATATAT', c='TATA', d='GCGTCGC'))
gives :
CGCTGCG
Store the results in a list
and retund the list
.
def reverse_complement(**seqs):
results=[]
for arg in seqs.values():
reverse=arg[::-1]
results.append(reverse)
return results
print(reverse_complement(a='CGTC', b='ATATAT', c='TATA', d='GCGTCGC'))
['CTGC', 'ATAT', 'TATATA', 'CGCTGCG']
To return the whole sequence (with the keys), return a dict:
def reverse_complement(**seqs):
reverse_dict = {}
for key in seqs.keys():
arg = seqs[key]
reverse_dict[key] = arg[::-1]
return reverse_dict
print(reverse_complement(a='CGTC', b='ATATAT', c='TATA', d='GCGTCGC'))
This gives:
{'a': 'CTGC', 'c': 'ATAT', 'b': 'TATATA', 'd': 'CGCTGCG'}
as the output.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.