yusuf yusuf - 1 year ago 79
Python Question

getting specific characters from complex strings in python

I have such strings:


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?


Answer Source

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'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download