Consider the below piece of code:
searchList=["hello", "hello world", "world"]
pattern = 'hell'
matchingList = [t for t in searchList if re.match(pattern, t)]
The above code works fine in Jython 2.4.3 but fails in lower versions of Jython with this error:
ValueError: iterator indices must be consecutive ints starting at 0
Any workarounds?
With this below work around, am gettign the same error:
for t in searchList:
if re.match(pattern, t):
matchingList.append(t)
Error seen in Jython 2.1
The code works fine on cpython 2.3.5, 2.2.3, 2.1.3, and 2.0 as well as jython 2.2.1, 2.2, and 2.1. List comprehensions are only available in 2.0+. Instead, you can write:
That being said, even 2.4 is ancient and has been unsupported for quite a while (this means that you must manually apply and adapt all security patches since then to have a secure system). The Python versions you’re catering to are more than a decade old, and almost certainly riddled with security vulnerabilities. Consider deprecating Python 2.5 and older.