Can PyCharm suggest use of list comprehension in Intentions?

Hi,

I'm just starting with PyCharm and coming from a Visual Studio / ReSharper background, I'm used to ReSharper making lots of useful code improvement suggestions.

I was hoping PyCharm would do the same - e.g. to suggest use of list comprehension when it detects it could be used.

My install is NOT doing this - do I need to configure anything? 

I've looked under Intentions, but can't see anything obvious.

5 comments
Comment actions Permalink

PyCharm should obviously do that, code completion/suggestions is one of the main features.

Do you have interpreter selected? Can you run your code? Please provide description of your setup, screenshots and examples to demonstrate the issue.

0
Comment actions Permalink

Hi Andrew, thanks for responding.

> PyCharm should obviously do that, code completion/suggestions is one of the main features.

Agreed, the main reason I was looking forward to using PyCharm was to learn better Python from its suggestions.

> Do you have interpreter selected?

Well, I _think_ I do - we're using v2.7 on our project.  Does this look right?

 

> Can you run your code

Yes, I've reproduced a simple example of the code below.   If I understand correctly, PyCharm should suggest that I can convert the first 3 lines  in `create_array` using list comprehension?

 

```

def create_array():

values = []

for i in range(5):
values.append(i)

return values

if __name__ == '__main__':
values = create_array()
print values

```

 

0
Comment actions Permalink

Ok, thanks for the example. Intentions can convert list comprehension to a for loot, but not vice versa, unfortunately. The closest thing we have is list comprehension live template, e.g. try typing `compl` after `values = []` and press enter on list comprehension template.

But that's not what you want, sorry.

0
Comment actions Permalink

Almost forgot - Please feel free to submit a corresponding feature request to our issue tracker using the link https://youtrack.jetbrains.com/issues and let us know if you need any help.

0
Comment actions Permalink

Thanks for your feedback, Andrey.

As suggested, I've added a YouTrack for this issue - https://youtrack.jetbrains.com/issue/PY-38259

0

Please sign in to leave a comment.