An ode to re.finditer()

R

Robert Oschler

I figured I'd utter some words of praise for re.finditer(). It's such a
great feeling, when you come across a single statement that does everything
you want in two lines of code:

for g in re.finditer(pattern, string):
do_something_to_g(g)

In two lines of code I can break out all the sub-strings I need with a
regular expressions pattern, and have each of them operated upon by a
function.

Nice.

[Note: Python 2.2.3 or better is needed to use re.finditer()]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top