split()
takes an optional maxsplit
argument:
>>> s = " 0000000125 1196672 9.2 The Shawshank Redemption (1994)"
>>> s.split()
['0000000125', '1196672', '9.2', 'The', 'Shawshank', 'Redemption', '(1994)']
>>> s.split(maxsplit=3)
['0000000125', '1196672', '9.2', 'The Shawshank Redemption (1994)']
In Python 2, you need to specify the maxsplit
argument as a positional argument:
>>> s = " 0000000125 1196672 9.2 The Shawshank Redemption (1994)"
>>> s.split(None, 3)
['0000000125', '1196672', '9.2', 'The Shawshank Redemption (1994)']