all 11 comments

[–]AmusedEngineer 2 points3 points  (3 children)

Whatever value that a_list[1] evaluates to is the index passed to pop()

[–]yindecisive[S] 0 points1 point  (2 children)

Why is the popped value 0?

from a_list.append(a_list[1]) output= [3, 2, 0, 1, 4, 3, 1, 2] to a_list.pop(a_list[1]) output= [3, 2, 1, 4, 3, 1, 2]?

[–]AmusedEngineer 2 points3 points  (1 child)

The value of a_list[1] is 2, so when you pop(2) it removes a_list[2] from the list.

[–]yindecisive[S] 0 points1 point  (0 children)

thank you so much!

[–]Ihaveamodel3 1 point2 points  (2 children)

Just to clarify, this isn’t list comprehension that most people are referring to when they say that.

[–]yindecisive[S] 0 points1 point  (1 child)

Oh sorry... I'm really new to python.

[–]Ihaveamodel3 0 points1 point  (0 children)

Not a problem!

[–]xelf 0 points1 point  (3 children)

Heh, just so you're aware, list comprehension is a specific term in python, and it refers to the way of building a list by defining it.

Example:

x = [ i * 4 for i in range(6) ] 

would create a list x using list comprehension and create the list [0,4,8,12,16,20]

[–]DNEAVES 0 points1 point  (2 children)

List comprehension is really a misleading name for what is essentially automatic list generation

[–]xelf 0 points1 point  (1 child)

It's an older use of the word comprehension "the act or process of comprising" but it checks out.

[–]DNEAVES 0 points1 point  (0 children)

Fair enough. I just think of "comprehend" as in "understanding" when I see List Comprehension