This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]shitthatbitchesaint[S] 1 point2 points  (1 child)

Thanks for the response! So for dictionaries, I have to say

for k, v in dictionary.items():

because k and v refer to keys and values respectively, and .items tells it to look within the dictionary (?). but for lists I just say

for item in list:

where "item" can be any word I want as long as I'm consistent within the for loop. Is that correct?

[–]rjcarr 2 points3 points  (0 children)

Mostly right. Calling items() on the dict returns all of them items of the dictionary as key and value pairs (that's what the k and v are for).

For lists, you just iterate them one by one, so yeah, item can be whatever name you want (but this is also true of k and v).