Reputation: 80
A particular function/command of mine has started behaving strangely. Remove items from a nested list based on comparing values obtained from another nested list
a = [[1,2,3,4,5],[3,4,5,6,7,8,9],[5],[1,2,3,6,7,8,9]]
b = [[1,4],[6,9]]
print ([[i for i in s if not any(l <= i <= h for l, h in b)] for s in a])
Expected Output :
[[5], [5], [5], []]
Output in IDLE and codeskulptor (https://py3.codeskulptor.org/) :
[[5], [5], [5], []]
Output in Spyder IDE (in the Ipython console) is
[[], [], [], []]
Code was working fine till EoD yesterday. I started my laptop again today and started having this discrepancy. My python installation is via Anaconda. Python version 3.6.6 (shown in both IDLE and Spyder) Spyder version is 3.3.1
I have tried restarting the laptop a couple of times as a last resort but can't seem to find the reason for this discrepancy
Upvotes: 0
Views: 847
Reputation: 34136
(Spyder maintainer here) I can reproduce the output you're seeing in Spyder if previous to your code I run
from numpy import any
Since you claim that you're getting the same result after a kernel restart, that means you have activated the option present in
Tools > Preferences > IPython console > Graphics > Automatically load Pylab and NumPy modules
So please deactivate that option to get the expected output with the builtin any
.
Upvotes: 2