I'm using the python split method to manipulate with some filepaths. It looks like this, where I split the filepath to make a list, and then do some slicing on it:
array = "/home/ask/Git/Zeeguu-API/zeeguu_core/user_statistics/main.py"
split = array.split("/")
Which outputs:
['', 'home', 'ask', 'Git', 'Zeeguu-API', 'zeeguu_core', 'user_statistics', 'main.py']
The issue here is the little empty string in the beginning of the list, it makes sense that it is there but is annoying, and messes with the slicing that I want to do.
How can I split, but omit the empty strings? I would rather like to avoid having to do a O(n) operation, just to filter out the empty string, I really hope there is somehow to avoid it in the call to split()
array[1:].split("/")? orarray.split("/")[1:]?/in the path conveys information (it distinguishes a relative path from an absolute one), right? What are you trying to do with the split-up path information? Do you also want to omit empty path components in the middle (like infoo//bar)? Why? Have you considered using the built-in standard library support for manipulating file paths (pathlib, or at the very leastos.path)?