Saturday, March 25, 2017

Python is Crap Compared to Perl

When it comes to text processing.

Okay, this is a known fact. Question - why hasn't this gotten more attention?

How would you do this?

string : "Mary had a little lamb1" --> "Mary had1 a little lamb" . Okay, a lame example - I want to append a 1 after a d or a b. In perl, it's as simple as s/([db])/${1}1/g . What is it in Python????

Here's a guy who barely scratches the surface. A valiant attempt though .. better half a loaf.

What is the equivalent of using curly braces for variable names within interpolated strings?????

Anyways, here's one way of accomplishing this particular task (Thanks!) :

re.sub( r"(?P)[db])" , r"\g1" , myString )

Enjoy..

No comments: