Deutsch   English   Français   Italiano  
<mailman.85.1730843499.4695.python-list@python.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: dn <PythonList@DancesWithMice.info>
Newsgroups: comp.lang.python
Subject: Re: Two python issues
Date: Wed, 6 Nov 2024 10:41:59 +1300
Organization: DWM
Lines: 60
Message-ID: <mailman.85.1730843499.4695.python-list@python.org>
References: <700403c2-e052-4670-b2ec-eaf9b4babada@pandora.be>
 <CANy1k1iML9=cKxhQfASBZDwqc_4N_E66MgXhddPf6zna3G-ckw@mail.gmail.com>
 <8faeaf6f-0110-41bd-9e21-1fc4d57b42ae@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de HAMVfsCkeEKvjmCjITPO8whEf+zIgZ084+0cKTqot+sg==
Cancel-Lock: sha1:FIt8Z+qCH0XI4xcCj9VV9dHm80Y= sha256:NbIjLsr8cfxlHkR/Tn6VfPRfjl07NCPyMDXWn3bF/kk=
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
 reason="2048-bit key; unprotected key"
 header.d=danceswithmice.info header.i=@danceswithmice.info
 header.b=iZAkOB7q; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.014
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; "python's": 0.05; 'cpu':
 0.07; '=dn': 0.09; 'example:': 0.09;
 'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
 0.09; 'questions:': 0.09; 'situations': 0.09; 'subject:python':
 0.10; '"not': 0.16; '"where': 0.16; '(will': 0.16; 'apis': 0.16;
 'duplication': 0.16; 'found"': 0.16; 'languages.': 0.16; 'message-
 id:@DancesWithMice.info': 0.16; 'option.': 0.16;
 'received:51.254': 0.16; 'received:51.254.211': 0.16;
 'received:51.254.211.219': 0.16; 'received:cloud': 0.16;
 'received:rangi.cloud': 0.16; 'says:': 0.16; 'wrote:': 0.16;
 'problem': 0.16; 'subject:issues': 0.19; 'to:addr:python-list':
 0.20; 'idea': 0.24; 'seems': 0.26; 'bit': 0.27; '>>>': 0.28;
 'think': 0.29; 'error': 0.29; 'header:User-Agent:1': 0.30;
 'answers': 0.32; 'objects': 0.32; 'python-list': 0.32;
 'returning': 0.32; 'said,': 0.32; 'header:Organization:1': 0.32;
 'but': 0.32; "i'm": 0.33; 'there': 0.33; 'header:In-Reply-To:1':
 0.34; 'requires': 0.34; 'item': 0.35; 'currently': 0.37; 'using':
 0.37; 'received:192.168': 0.37; 'url-ip:151.101.0.223/32': 0.38;
 'url-ip:151.101.128.223/32': 0.38; 'url-ip:151.101.192.223/32':
 0.38; 'url-ip:151.101.64.223/32': 0.38; 'both': 0.38; 'use': 0.39;
 'two': 0.39; 'still': 0.40; '(see': 0.40; 'should': 0.40;
 'reference': 0.60; 'method': 0.61; 'above': 0.62; 'skip:b 20':
 0.63; 'your': 0.64; 'received:51': 0.64; 'time.': 0.66; 'bad':
 0.67; 'apply.': 0.69; 'refers': 0.69; 'sequence': 0.69; 'within':
 0.69; 'content': 0.72; 'little': 0.73; 'major': 0.78; 'position':
 0.81; 'study': 0.82; 'indicates': 0.84; 'similarly': 0.84;
 'thus,': 0.84; 'performs': 0.93
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud DA1268264
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
 s=staff; t=1730842924;
 bh=cB9S2zxBjN6e6rDv9ibZOdhB59p39Q9cKEw2JHACk0c=;
 h=Date:From:Subject:To:References:In-Reply-To:From;
 b=iZAkOB7qKQowLHb2g7GgZ06onXPhmb671BHoMRmerK3T1llcnQjq0hVtFjrnmxBGM
 bDkECSr/9vuYoFd1qGckxrW7ykQneIMUN4JG/WILKrvjkDOF1zNuQuQg5/veSlRzfT
 SqRCMSu9ItV5SGEoCRGyq44QrV4NmX/MeOXgBjSd3+aEfkCMmM4j3vQBy9bXyixwWO
 3KimHxeKNSJCwhqDXyPsPx/GVOvTqQPhEscf20NZObZuYsNuPcWB5OAxJoszWISB4I
 9HS0F+oBBJscKn0vOqSzR5x7DpvpyNC1Ll1mT42cMGkCItPHRu/YRzZ7WM6En0RQ4E
 3B0SU1Zn+Cc/w==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <CANy1k1iML9=cKxhQfASBZDwqc_4N_E66MgXhddPf6zna3G-ckw@mail.gmail.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
 <python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
 <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
 <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <8faeaf6f-0110-41bd-9e21-1fc4d57b42ae@DancesWithMice.info>
X-Mailman-Original-References: <700403c2-e052-4670-b2ec-eaf9b4babada@pandora.be>
 <CANy1k1iML9=cKxhQfASBZDwqc_4N_E66MgXhddPf6zna3G-ckw@mail.gmail.com>
Bytes: 6530

On 6/11/24 10:08, Jason Friedman via Python-list wrote:
>>
>> (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!).
>>
> 
> I'm not sure if this answers your objection but the note in the
> documentation (https://docs.python.org/3/library/stdtypes.html#str.find)
> says:
> 
> The find() method should be used only if you need to know the position of
> sub.
> 
> I think the use case above is a little bit different.


Not really, there are two questions:

1. is x in sequence (or in this case "not in")
2. where is x within sequence (find())

There are situations where one might be used, similarly where the other 
will be used, and still more where both apply.

That said, and with @Cameron's observation, the idea that a function's 
return-value (appears to) performs two functionalities is regarded as a 
'code-smell' in today's world - either it indicates "found" or it 
indicates "where found" (see also various APIs which return both a 
boolean: success/fail, and a value: None/valid-info).

The problem with the third scenario being that purity suggests we should 
use both (1) and (2) which seems like duplication - and is certainly 
going to take more CPU time.
(will such be noticeable in your use-case?)

Backward-compatibility... ('nuff said!)


With reference to the OP content about slicing:
- Python's memory-addressing is different from many other languages. 
Thus, requires study before comparison/criticism
- there are major differences in what can be accomplished with mutable 
and immutable objects

-- 
Regards,
=dn