What does enumerate(['a', 'b'], start=1) yield?
-
A
(0, 'a') and (1, 'b')
-
B
(1, 'a') and (2, 'b')
Correct answer
-
C
(1, 'b') and (2, 'a')
-
D
('a', 1) and ('b', 2)
Correct answer
B. (1, 'a') and (2, 'b')
18 views
Explanation
enumerate pairs a counter with each item, so for i, item in enumerate(...) replaces manual index tracking. The start parameter sets the first number.
Reference
Asked in: NTS, Python Developer Interviews
Doubts & discussion
Not sure why the answer is B? Ask here and get an explanation.
Ask a doubt about this MCQ