Fastest way to add enumerate statement to for loop in PyCharm?

Here's something I run into several times per day.

I have a statement like 

for x in my_iterable:

and I would like to change it to

for i, x in enumerate(my_iterable):

What is the fastest way to accomplish this in PyCharm? 

I am asking this because while the tab/enter completion and auto-insertion of parenthesis in PyCharm are usually great, they make this particular transformation kind of awkward to accomplish. Start with the first statement and try to modify it into the second by typing and you'll see what I mean. I am thinking maybe there's an easier way to do this that I'm not aware of.

1 comment
Comment actions Permalink

I'm not sure about transforming the existing statement, but you can use live templates to easily write such statements from scratch.

Check in [Preferences | Editor | Live Templates | Python]

There's a built-in live template for that called "itere", very convenient to use in my opinion.

0

Please sign in to leave a comment.