PY3.C0207
Use maxsplit arg
Emitted when accessing only the first or last element of str.split(). The first and last element can be accessed by using str.split(sep, maxsplit=1)[0] or str.rsplit(sep, maxsplit=1)[-1] instead.
Noncompliant Code:
コピー
url = "www.example.com"
suffix = url.split(".")[-1]
Compliant Code:
コピー
url = "www.example.com"
suffix = url.rsplit(".", maxsplit=1)[-1]
Additional details
Be aware that the performance improvement from not splitting the string so many times will only be realized in cases presenting more instances of the splitting character than the minimal example here.