Sujet : Re: A technique from a chatbot
De : michael.stemper (at) *nospam* gmail.com (Michael F. Stemper)
Groupes : comp.lang.pythonDate : 03. Apr 2024, 23:36:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <uuki4v$5i2o$1@dont-email.me>
References : 1 2
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 03/04/2024 13.45, Gilmeh Serda wrote:
On 2 Apr 2024 17:18:16 GMT, Stefan Ram wrote:
first_word_beginning_with_e
Here's another one:
def ret_first_eword():
... return [w for w in ['delta', 'epsilon', 'zeta', 'eta', 'theta'] if w.startswith('e')][0]
...
ret_first_eword()
'epsilon'
Doesn't work in the case where there isn't a word starting with 'e':
>>> def find_e( l ):
... return [w for w in l if w.startswith('e')][0]
...
>>> l = ['delta', 'epsilon', 'zeta', 'eta', 'theta']
>>> find_e(l)
'epsilon'
>>> l = ['The','fan-jet','airline']
>>> find_e(l)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in find_e
IndexError: list index out of range
>>>
-- Michael F. StemperIf it isn't running programs and it isn't fusing atoms, it's just bending space.