Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #196959
| From | Raymond Boute <raymond.boute@pandora.be> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Two python issues |
| Date | 2024-11-05 15:48 +0100 |
| Message-ID | <mailman.80.1730839406.4695.python-list@python.org> (permalink) |
| References | <700403c2-e052-4670-b2ec-eaf9b4babada@pandora.be> |
L.S.,
Python seem to suffer from a few poor design decisions regarding strings
and lists that affect the elegance of the language.
(a) An error-prone "feature" is returning -1 if a substring is not found
by "find", since -1 currently refers to the last item. An example:
>>> s = 'qwertyuiop'
>>> s[s.find('r')]
'r'
>>> s[s.find('p')]
'p'
>>> s[s.find('a')]
'p'
>>>
If "find" is unsuccessful, an error message is the only clean option.
Moreover, using index -1 for the last item is a bad choice: it should be
len(s) - 1 (no laziness!).
Negative indices should be reserved for elements preceding the element
with index 0 (currently not implemented, but a must for orthogonal
design supporting general sequences).
(b) When using assignment for slices, only lists with the same length as
the slice should be acceptable, otherwise an error should be given.
Anything that re-indexes items not covered by the slice is against the
essential idea of assignment. For changes that imply re-indexing (e.g.,
inserting a list longer than the slice), Python offers cleaner solutions.
Comments are welcome.
With best regards,
Raymond
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Two python issues Raymond Boute <raymond.boute@pandora.be> - 2024-11-05 15:48 +0100
Re: Two python issues Piergiorgio Sartor <piergiorgio.sartor.this.should.not.be.used@nexgo.REMOVETHIS.de> - 2024-11-05 22:27 +0100
Re: Two python issues (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-05 21:56 +0000
csiph-web