Python for beginners or not? [was Re: syntax difference]
Alister
alister at 1
Mon Jun 25 10:10:18 EDT 2018
To: Abdur-Rahmaan Janhangeer
From: Alister <alister.ware at ntlworld.com>
On Mon, 25 Jun 2018 11:36:25 +0400, Abdur-Rahmaan Janhangeer wrote:
> i think he means like for a loop to iterate over a list you might do
>
> list = [1,2,3]
> for i in range(len(list)):
> print(list[i])
>
>
> but the you might as well go for the simpler :
>
>
> for elem in list:
>
> print(elem)
>
> Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ
>
>
>
for i in range(len(list)): is a python anti-pattern it is almost a 100%
guarantee that you are doing something wrong*
*as with all rules of thumb there is probably at least 1 exception that
the python experts will now point out.
--
Lend money to a bad debtor and he will hate you.
--- BBBS/Li6 v4.10 Toy-3
* Origin: Prism bbs (1:261/38)
More information about the Python-list
mailing list