Reputation: 7684
Anyone knows how does the split function work in python? I mean, does it read the string char by char and then evaluates the code or it has another way of working? I've read the doc but it doesn't mention.
EDIT
For those who are curious like me, just check here. It should be on the 147th line as Chris stated.
Upvotes: 1
Views: 3619
Reputation: 20550
Speaking as of 3.2, there are several split()
implementations. First of all, split()
with no arguments has its own implementation, since it has slightly different semantics than other splits. When a split string is given, there are two possible implementations: one for a single character separator and one for other strings. The one character implementation simply scans through the string and appends chunks to a list. For longer strings, the algorithm is the same, but search performed with Bloom filters.
Upvotes: 3
Reputation: 48795
If you check out the python source code (I used 2.7.1, but I doubt the location changed in the 3.x series), the full implementation can be found at $src_dir/Objects/stringlib/split.h
. The function's name is stringlib_split
and in 2.7.1 can be found on line 147.
Upvotes: 3