Issue 13755: str.endswith and str.startswith do not take lists of strings (original) (raw)

Issue13755

Created on 2012-01-10 04:09 by py.user, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg151002 - (view) Author: py.user (py.user) * Date: 2012-01-10 04:09
>>> 'abcd'.endswith(['a', 'b']) Traceback (most recent call last): File "", line 1, in TypeError: Can't convert 'list' object to str implicitly >>> it would be nice like in str.join >>> ''.join(('a', 'b')) 'ab' >>> ''.join(['a', 'b']) 'ab' >>> ''.join({'a', 'b'}) 'ab' >>> ''.join({'a': 1, 'b': 2}) 'ab' >>>
msg151011 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-01-10 11:21
No, but they take tuples: >>> 'abcd'.endswith(('a', 'b')) False >>> 'abcd'.endswith(('c', 'd')) True Suggest closing as out of date.
msg151013 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2012-01-10 12:34
It seems like a set would make more sense than a tuple. And if tuples, why not lists? Not that it matters much, since I doubt it's worth changing in either case. It's easy enough for the caller to convert.
History
Date User Action Args
2022-04-11 14:57:25 admin set github: 57964
2012-01-10 12:42:06 rhettinger set status: open -> closedresolution: rejected
2012-01-10 12:34:46 eric.smith set nosy: + eric.smithmessages: +
2012-01-10 11:21:42 mark.dickinson set versions: + Python 3.3, - Python 3.1nosy: + mark.dickinsonmessages: + type: behavior -> enhancement
2012-01-10 04:09:28 py.user create