Any better way for this removal? [typo correction]
Tim Chase
python.list at tim.thechases.com
Sat Nov 7 14:51:24 EST 2020
On 2020-11-07 10:51, Tim Chase wrote:
> from string import ascii_lowercase
> text = ",".join(ascii_lowercase)
> to_throw_away = 5
[derp]
For obvious reasons, these should be s/\<n\>/to_throw_away/g
To throw away the trailing N delimited portions:
> new_string = text.rsplit(',', n)[0]
new_string = text.rsplit(',', to_throw_away)[0]
and to remove the leading N fields
> new_string = text.split(',', n)[-1]
new_string = text.split(',', to_throw_away)[-1]
-tkc
More information about the Python-list
mailing list