yusuf yusuf - 9 days ago 5
Python Question

getting specific characters from complex strings in python

I have such strings:

ye<V><vn:inf><N><0><V><cpl:pres><3s>
çok<Postp:adv:ablC><0><N><0><V><cpl:pres><3s>
yağ<N><li><Adv><0><N><0><V><cpl:evid><3s>


And I want to extract;

ye, V, 3s
çok, Postp:adv:ablC, 3s
yağ, N, 3s


I have hundreds millions of such strings. What can be the best, efficient, and fastest way to do it? Can you show an example?

Thanks,

Answer

Try this:

l = s.split('<')
'{}, {}, {}'.format(l[0], l[1][:-1], l[-1][:-1])

Example of output:

>>> s = 'ye<V><vn:inf><N><0><V><cpl:pres><3s>'
>>> l = s.split('<')
>>> '{}, {}, {}'.format(l[0], l[1][:-1], l[-1][:-1])
'ye, V, 3s'