bitbybit on Nostr: my_list_to_look_through = [2,7,1,9] number_items_in_list_counter = 0 for x in ...
my_list_to_look_through = [2,7,1,9]
number_items_in_list_counter = 0
for x in my_list_to_look_through:
number_items_in_list_counter +=1
Every time the loop occurs it will iterate over the list to the next item. "x" can be any variable i, j,k, younginter, it's just a place holder. every time the loop executes it will add 1 to the number_items_in_list_counter. In this case it will equal 4.
Another example:
my_list_to_look_through = [2,7,1,9]
empty_container = [ ]
for x in my_list_to_look_through:
empty_container.append(x)
This will take the first item out of my_list_to_look_through and add it into the empty_container list. It will go through the loop, append 2 to empty_container, then 7, then 1, then 9.
Now
Previously defined
my_list_to_look_through = [2,7,1,9]
And our new container has the same
empty_container = [2,7,1,9]
number_items_in_list_counter = 0
for x in my_list_to_look_through:
number_items_in_list_counter +=1
Every time the loop occurs it will iterate over the list to the next item. "x" can be any variable i, j,k, younginter, it's just a place holder. every time the loop executes it will add 1 to the number_items_in_list_counter. In this case it will equal 4.
Another example:
my_list_to_look_through = [2,7,1,9]
empty_container = [ ]
for x in my_list_to_look_through:
empty_container.append(x)
This will take the first item out of my_list_to_look_through and add it into the empty_container list. It will go through the loop, append 2 to empty_container, then 7, then 1, then 9.
Now
Previously defined
my_list_to_look_through = [2,7,1,9]
And our new container has the same
empty_container = [2,7,1,9]