Simple question:
Matplotlib has a function that returns two values:
locs,label = plt.yticks()
Pylint complains about this line, telling me “Used builtin function map”. So I went to pylint site and found this: http://pylint-messages.wikidot.com/messages:w0141
So, I’m trying to fix this warning using list comprehension. But what is the correct form?
[(locs,label) for plt.yticks()]
is not working.
Thanks!
EDIT: I made a simple test script to try to show the problem, and the problem was one line below:
#!/usr/bin/python
""" docstring """
import matplotlib.pyplot as plt
LOCS, LABEL = plt.yticks()
plt.yticks(LOCS, map(lambda x: "%.2f" % x, LOCS)) # offending line
print(LOCS)
So duh, I was looking on the wrong line. How this lambda can be adjusted to list comprehension? Thanks
Is the correct way to receive two variables from a function. You could receive it as a single variable, and work with the tuple object, but that would be pointless.
It’s possible that pylint is complaining about
plt.yticks. Apart from it being out of your control, it is not in general preferable to use a list comprehension instead ofmap, just in a wide variety of cases.In the case of
plt.yticks(LOCS, map(lambda x: "%.2f" % x, LOCS)), a list comprehension is likely to be more readable, and may be faster.