This is just checking how many parts the path has. The first part is always
/
.from pathlib import Path from urllib.parse import urlparse def how_many(url): return len(Path(urlparse(url).path).parts) - 1 print(how_many("http://{ }/something/{ }/{ }/{ }/{ }"))
Output:5
You can also do this to count the parts:len(Path("http://{ }/something/{ }/{ }/{ }/{ }".removeprefix("http://")).parts) - 1
str.removeprefix
was added since Python 3.9
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!