Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <mailman.63.1712158372.3468.python-list@python.org>
Deutsch   English   Français   Italiano  
<mailman.63.1712158372.3468.python-list@python.org>

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

Path: ...!news.mixmin.net!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Subject: RE: A technique from a chatbot
Date: Wed, 3 Apr 2024 11:32:44 -0400
Lines: 89
Message-ID: <mailman.63.1712158372.3468.python-list@python.org>
References: <chatbot-20240402181409@ram.dialup.fu-berlin.de>
 <fvstdk-607.ln1@lazy.lzy>
 <7d38d9e2-78fb-43af-971f-e0d4afb8b039@tompassin.net>
 <01d501da8587$8dd66c50$a98344f0$@gmail.com>
 <435c439b-148b-4440-b2d2-ea3611679216@tompassin.net>
 <001901da85dc$2cecd9b0$86c68d10$@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de DFjJnKNB1WuauTjPvxHZCQ67VDWTY7lsR4FiCIg2wW0Q==
Cancel-Lock: sha1:fBibC47DRW1dCm0dBVeKpbGpHAs= sha256:vAckpaMWz+0jfEj+wJSN2D+f1CB0/eSVENhNYbfwhnc=
Return-Path: <avi.e.gross@gmail.com>
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=gmail.com header.i=@gmail.com header.b=LlOJ4BcN;
 dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.010
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'def': 0.04; '3.8': 0.05;
 'fairly': 0.05; 'variable': 0.05; 'intermediate': 0.07; 'loop':
 0.07; 'matching': 0.07; 'suggestion': 0.07; 'received:108': 0.09;
 'received:mail-qk1-x72e.google.com': 0.09; 'steps': 0.11;
 'url:mailman': 0.15; "'e'": 0.16; '2024': 0.16; 'avi': 0.16;
 'calculations': 0.16; 'cases,': 0.16; 'compiled': 0.16;
 'confused': 0.16; 'constructed': 0.16; 'found.': 0.16; 'goto':
 0.16; 'gross': 0.16; 'none)': 0.16; 'nothing.': 0.16; 'sadly,':
 0.16; 'variable,': 0.16; 'variant': 0.16; 'ways.': 0.16; 'wrote:':
 0.16; 'problem': 0.16; 'python': 0.16; 'instead': 0.17;
 'probably': 0.17; 'message-id:@gmail.com': 0.18; 'to:addr:python-
 list': 0.20; 'all,': 0.20; 'returns': 0.22; 'version': 0.23;
 'code': 0.23; 'skip:p 30': 0.23; 'skip:- 10': 0.25; 'url-
 ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
 'url:listinfo': 0.25; 'url-ip:188.166/16': 0.25; 'seems': 0.26;
 'pattern': 0.26; 'wednesday,': 0.26; 'else': 0.27; 'function':
 0.27; '>>>': 0.28; 'am,': 0.31; 'url-ip:188/8': 0.31; 'fine.':
 0.32; 'python-list': 0.32; 'but': 0.32; 'there': 0.33; 'header:In-
 Reply-To:1': 0.34; 'received:google.com': 0.34; 'running': 0.34;
 'complex': 0.35; 'runs': 0.35; 'yes,': 0.35;
 'from:addr:gmail.com': 0.35; 'people': 0.36; 'necessarily': 0.37;
 'special': 0.37; 'subject:from': 0.37; 'could': 0.38; 'read':
 0.38; 'quite': 0.39; 'least': 0.39; 'single': 0.39; 'text': 0.39;
 "we've": 0.39; 'list': 0.39; 'use': 0.39; 'on.': 0.39; 'still':
 0.40; 'beginning': 0.40; 'done.': 0.40; 'match': 0.40;
 'something': 0.40; 'want': 0.40; 'should': 0.40; 'including':
 0.60; 'from:': 0.62; 'to:': 0.62; 'seen': 0.62; 'finally': 0.62;
 'gain': 0.62; 'come': 0.62; 'simply': 0.63; 'complete': 0.64;
 'clear': 0.64; 'full': 0.64; 'others,': 0.64; 're:': 0.64; 'less':
 0.65; 'shows': 0.67; 'back': 0.67; 'bad': 0.67; 'and,': 0.69;
 'counter': 0.69; 'it:': 0.69; 'conditions': 0.70; 'experience.':
 0.70; 'truly': 0.70; 'longer': 0.71; 'skip:f 20': 0.75; 'sent:':
 0.78; 'returned': 0.81; 'points': 0.84; 'eastern': 0.84; 'poorly':
 0.84; 'posed': 0.84; 'caused': 0.86; 'return,': 0.91;
 'underneath': 0.91; 'immediate': 0.97
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1712158369; x=1712763169; darn=python.org;
 h=thread-index:content-language:content-transfer-encoding
 :mime-version:message-id:date:subject:in-reply-to:references:to:from
 :from:to:cc:subject:date:message-id:reply-to;
 bh=ESfYUssCRqBIT6jNC24ZzD70URQGOF2LYF84V6kq+6Y=;
 b=LlOJ4BcNfLqMv3ULjOIhN/Q22ZrIr7B8ZAhkFhNjLyGRciypmhe8gO9l2XVSWWV9s0
 IfgCsn3OC3p6qUiSJYSxTls4quHfMoDOofHF1g+GKrKXETbbJcHytUOavBbZD9wnDCdM
 O0ES4Bdjmcg/P/EJCFm+iQZ2cgJcnRpdIBOopAoeyDDkhKS6EmbAVeGw3iuXxMmedUj5
 jbkE9yt4eY15HM9MBagpu2rHDjoAV71LwU0LNkcBFCUFw4znBGEE/K/K1KUvXfmCU28b
 rIoM5V4IB9JRhxwaPH3U2E5TWDgAY+/9br1m1rTbarjkTa5uo+2a+jacaUrP2c8KMAwG
 cRkg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1712158369; x=1712763169;
 h=thread-index:content-language:content-transfer-encoding
 :mime-version:message-id:date:subject:in-reply-to:references:to:from
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=ESfYUssCRqBIT6jNC24ZzD70URQGOF2LYF84V6kq+6Y=;
 b=TtHEtrjjA1FtZuYR8boVxIGqZoR3MBCtE0iP+9DzEQUeQEzD09jJ9xhveyZkCJChlD
 zmz2TRqxRFZdGFIhuHDplNLHEYghLtGgzVNexBMUc8GwZCQo8xTmweeOdRq0fFzih3wY
 w/HLOw4Jo+Z6lx5ZpeeYSz47smdvg9GsgHGjHPXsarpshrUkLETMuvS1NSlNUAf8vQp3
 lBCavnv21TR0hNsiK4A5tvlK2aENZJZh6EgkVLBeBlU/qSJurCjUdrHSpBkygNfibX/p
 e0PbILgKFeJYW37k0EBdbrHZoTBfCZWytZbsh9/TF8cL8soW20/GUNMugQj7OoRxPlir
 eGQA==
X-Forwarded-Encrypted: i=1;
 AJvYcCWM1yGTPaGZRUSCZJCR6D/AxQWJ2sRAX6mbuYlhK1BRNtLnI9RoL+ti/aVy9ms05PKPppNtWoP5ohWEk3+XEKhbryEn6FnW
X-Gm-Message-State: AOJu0YzuPUvnFe+lvCwSAxTbdvZ+hdncUPkoE0hrmTIIifysxZQ8Y/k2
 W+0pa4+gv7hI5B9qdYqOjVra5assDU9GYzLaHnvtDb5kh9B+b7Xz5IiDCmN1
X-Google-Smtp-Source: AGHT+IGwG0r2AL5+1wiSVaR3Lr/5xqi2rM8U4Iq6pCzAYlXCxMHvrJTiw6ayENpx4M4qc2RXvAjhFA==
X-Received: by 2002:a05:620a:d83:b0:78b:ea1a:4171 with SMTP id
 q3-20020a05620a0d8300b0078bea1a4171mr8731076qkl.36.1712158369198; 
 Wed, 03 Apr 2024 08:32:49 -0700 (PDT)
In-Reply-To: <435c439b-148b-4440-b2d2-ea3611679216@tompassin.net>
X-Mailer: Microsoft Outlook 16.0
Content-Language: en-us
Thread-Index: AQG2as0aVd2VIulEmuXRHp684y8JCQJBvrQcAfnDloEBbJq5qQGVLTBOsWT3WtA=
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: <001901da85dc$2cecd9b0$86c68d10$@gmail.com>
X-Mailman-Original-References: <chatbot-20240402181409@ram.dialup.fu-berlin.de> <fvstdk-607.ln1@lazy.lzy>
 <7d38d9e2-78fb-43af-971f-e0d4afb8b039@tompassin.net>
 <01d501da8587$8dd66c50$a98344f0$@gmail.com>
 <435c439b-148b-4440-b2d2-ea3611679216@tompassin.net>
Bytes: 10319

Sadly, Thomas, this is not even all that new.

I have seen people do searches on the internet for how to do one thing at a
time and then cobble together some code that does something but perhaps not
quite what they intended. Some things are just inefficient such as reading
data from a file, doing some calculations, writing the results to another
file, reading them back in and doing more calculations and writing them out
again and so on. Yes, there can be value in storing intermediate results but
why read it in again when it is already in memory? And, in some cases, why
not do multiple steps instead of one at a time and so on.

How many people ask how to TEST the code they get, especially from an
AI-like ...?



-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
Behalf Of Thomas Passin via Python-list
Sent: Wednesday, April 3, 2024 7:51 AM
To: python-list@python.org
Subject: Re: A technique from a chatbot

On 4/3/2024 1:27 AM, AVI GROSS via Python-list wrote:
> I am a tad confused by a suggestion that any kind of GOTO variant is bad.
The suggestion runs counter to the reality that underneath it all, compiled
programs are chock full of GOTO variants even for simple things like
IF-ELSE.
> 
> Consider the code here:
> 
>>> def first_word_beginning_with_e( list_ ):
>>>       for word in list_:
>>>           if word[ 0 ]== 'e': return word
>>>       something_to_be_done_at_the_end_of_this_function()
> 
> If instead the function initialized a variable to nothing useful and in
the loop if it found a word beginning with e and it still contained nothing
useful, copied it into the variable and then allowed the code to complete
the loop and finally returned the variable, that would simply be a much less
efficient solution to the problem and gain NOTHING. There are many variants
you can come up with and when the conditions are complex and many points of
immediate return, fine, then it may be dangerous. But a single return is
fine.
> 
> The function does have a flaw as it is not clear what it should do if
nothing is found. Calling a silly long name does not necessarily return
anything.
> 
> Others, like Thomas, have shown other variants including some longer and
more complex ways.
> 
> A fairly simple one-liner version, not necessarily efficient, would be to
just use a list comprehension that makes a new list of just the ones
matching the pattern of starting with an 'e' and then returns the first
entry or None. This shows the code and test it:
> 
> text = ["eastern", "Western", "easter"]
> 
> NorEaster = ["North", "West", "orient"]
> 
> def first_word_beginning_with_e( list_ ):
>    return(result[0] if (result := [word for word in list_ if
word[0].lower() == 'e']) else None)
> 
> print(first_word_beginning_with_e( text ))
> print(first_word_beginning_with_e( NorEaster ))
> 
> Result of running it on a version of python ay least 3.8 so it supports
the walrus operator:
> 
> eastern
> None

The OP seems to want to return None if a match is not found.  If a 
Python function ends without a return statement, it automatically 
returns None.  So nothing special needs to be done.  True, that is 
probably a special case, but it suggests that the problem posed to the 
chatbot was not posed well.  A truly useful chatbot could have discussed 
many of the points we've been discussing.  That would have made for a 
good learning experience.  Instead the chatbot produced poorly 
constructed code that caused a bad learning experience.

========== REMAINDER OF ARTICLE TRUNCATED ==========