Enumerate - Intermediate Python Programming p.7

preview_player
Показать описание
Welcome to part 7 of the intermediate Python programming tutorial series. In this part, we're going to talk about the built-in function: enumerate.

A somewhat common task might be to attempt to attach an index value, or some other unique value to list items. It may be temping to use something a for loop over range(len(your_variable)), but this is usually not quite the right way.

Рекомендации по теме
Комментарии
Автор

enumerate also has the keyword arg 'start', which allows the index to start from any number - default = 0
your_list = [1, 2, 3]
for i, j in enumerate(your_list, 1):
print(i, j)

1 1
2 2
3 3

geoptus
Автор

I use the range(len()) all of the time. Thank you so much Sentdex your tutorials are helping me out a lot to become a more efficient programmer.

cheesandpinuts
Автор

You have a gift for teaching. thanks for all your videos.

ThinkSmartData
Автор

this is by far the easiest explanation have seen on the explanation of enumerate

sokiprialajonah
Автор

Thank you for your incredibly well constructed and clear videos.
I have probably learned more practical programming in the last week than all of my Electrical Engineering education.

luck america.

beckettman
Автор

The best use of 'enumerate' that I have seen so far is in getting the indices of a sorted list:
[ i[0] for i in sorted(enumerate(myList), key=lambda x: x[1]) ]

playful_batman
Автор

Wow! I am truly amazed by the content of ypur channel!! And all of it EXTREMLY EDUCATIONAL and well organized! AWSOME

azelbane
Автор

GREAT JOB OF EXPLAINING. Your videos are always very clear and easy to follow

spcl-vid
Автор

I came for Enum, but that's okay I learned about enumerate() anyway

shadow
Автор

Suggestion: how about finish up the intermediate tutorial developing a small app from scratch?

lecioufs
Автор

Finally get what enumerate does, been struggling for days trying to figure it out. THANK YOU!!!

krazyq
Автор

for i in enumerate(example):
print(*i)

sairajdas
Автор

Can you enumerate over the election results?

Crider
Автор

could you please show the short-cut key to add # in front of the lines? like what you did at 2:25 in the video

louieyizuo
Автор

Hi Sentdex, I was hoping you could answer another question for me, if I was going to make a haar cascade that detects specifically my face, can I use bigger images (than the 50x50 pixels used in the tutorial). Also can I put other peoples faces in the neg file, thanks

repaler
Автор

I really like this series. Thanks for making it!

stumblinzz
Автор

there is also possibility to get quite readable code without enumerate:

for i in example:
print(example.index(i), i)

as you know i accepts every value of example in order: from left to right. thats why you can access index of i by example.index(i) which will give you result equal to using enumerate function.

it works only thanks to order of iteration.

maybe it isn't best solution but maybe beginners will find out something new

(i'm sorry if my explanation and whole comment isn't understable, i'm not a good teacher and english isn't my primary language)

albertkisiel
Автор

please tell me if i had written is correct
for i in example
print(i, example[i])

hardikgarg
Автор

What are the advantages if I'll use enumerate? I used .index() since I have started to work with lists.

kommentiererei
Автор

[print(k, v) for k, v in new_dict.items()]

# output:
# 0 left
# 1 right
# 2 up
# 3 down

wlancer
join shbcf.ru