#Gorillas vs. Sharks:
You can't simply compare r and python, they're like, well, Gorillas and Sharks.
It's not as simple as: which is better?
And, it's often not the language that's better, but the quality of the code!
#Possible things that could be slowing execution: ###Things not specific to you:
- Beginner's language abuse: as a self-confessed beginner, you may be using the functions or functionality of Python incorrectly.
- Library abuse: Some libraries aren't exactly a walk in the park to use, you may not be using some of the libraries properly.
- Library quality: Assuming library quality is a bit naïve, the actual code behind the library may not be as optimised or good as the other language's implementation.
###Things specific to you:
- Regex: There's many regex being executed, which, is quite a time consuming process, this regex:
(?:(?=[.,:;?!) ])|(?<=\( ))
managed to register 3000 steps for me!
s = s.lower()
, if you're using certain characters in your content, this can have issues.
I'd recommend taking a look over at How do I do a case insensitive string comparison in Python?How do I do a case insensitive string comparison in Python?.
if n in re.split(r"[ :?.,]", s):
lc = re.split(r"(^| )" + n + "( |[!\",.:;?})\]])", s)[0]
What is n
, re
, lc
or s
? Your variable names are unclear and confusing to read.