There's An OPTIMIZED Way To Do THIS In Python (ft. enumerate)

preview_player
Показать описание
Here's a quick optimization that you can perform in Python with enumerate().

▶ Become job-ready with Python:

▶ Follow me on Instagram:

00:00 Intro
00:10 enumerate()
01:38 The tests
03:53 A good optimisation?
04:14 That’s it
Рекомендации по теме
Комментарии
Автор

For the occasions where "start" with enumerate has been really useful for me, I define the start as a variable because it depends on some other conditions. Then I refer to that variable via "start=". I think having the start value somewhere other than with "start=" is less readable, but each to their own, I guess.

cerealport
Автор

Loved the video! Which IDE is that tho?

xelxen
Автор

Correct me if I am incorrect, could you not have just done the following for the enumerate function?:
temp_list = list(enumerate(values, start=1))

HerculeanYT
Автор

Is it the same if you first time normal and then the “start=1” solution?
It’s not very accurate to benchmark like this.
First timed would be in worst condition, starting with the system that is not yet heated up.
Ideally this should be 2 separate programs and you should start it separate with a propped benchmarking tool that performs several heat up runs and then several measurement runs and calculate the average.

kamurashev
Автор

look at this code below
for key, group by groupby(enumerate(numbers, start=1), lambda x: x[1] - x[0])
i can't set i + 1) use start instead, it more readable

kite
Автор

Writing start= is especially better if you use the value more than once.

HoSza
Автор

Why I need to use that "enumerate" function instead of "for _ in sth" with definition of list_index = 0 and in the cycle I can just increment that index. Indexes often are not required in iterations.

the_huge_knight
Автор

Python 11 shaving off time, by making both implementations slower 🙃 @ 3:41

InterpretingYou