0

Hi Guys, Can anyone help me redo this, so it'll be a list comprehension instead?


def parseAnnotation(annotation):
ExonStartAndStop = []
d = annotation.split(',')
for i in d:
removeparenteses = i[1:-1]
numbers = removeparenteses.split('..')
ExonStartAndStop.append((int(numbers[0]),int(numbers[1])))
return ExonStartAndStop
example usage:
print parseAnnotation('(1834..2736)') ---> [(1834, 2736))

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Gribouillis
0

Here is a way

def parse(annotation):
    return list((int(x), int(y)) for (x,y) in (item.strip(" ()").split('..') for item in annotation.split(',')))

print parse('(1834..2736), (348..7734)')

""" my output -->
[(1834, 2736), (348, 7734)]
"""

Edit: try and use the [code] button in the editor window at the bottom of this page!
Edit: it seems that pyTony gave you another nice solution last month http://www.daniweb.com/software-development/python/threads/400630/1715515#post1715515

Edited by diafol: fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.