Nov-26-2022, 03:44 PM
(This post was last modified: Nov-26-2022, 04:27 PM by Yoriz.
Edit Reason: Added code tags
)
This code is to remove one item from a List of "names" until the List is empty using for loop. The program does not complete the List stopping before the list is empty. See output 5 items on original List. Only 3 items removed
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Simple Test to empty List using loop List_of_Users = [ 'josh' , 'admin' , 'cookie' , 'jerry' , 'jack' ] # print ( "Starting List Below:" ) print (List_of_Users) Size_of_List = len (List_of_Users) print ( f "The List contains {Size_of_List} members" ) for User in List_of_Users: List_of_Users.pop( 0 ) print ( f "The new List: {List_of_Users} " ) Size_of_List = len (List_of_Users) print ( f "The List contains {Size_of_List} members" ) print ("") |
Output:Starting List Below:
['josh', 'admin', 'cookie', 'jerry', 'jack']
The List contains 5 members
The new List: ['admin', 'cookie', 'jerry', 'jack']
The List contains 4 members
The new List: ['cookie', 'jerry', 'jack']
The List contains 3 members
The new List: ['jerry', 'jack']
The List contains 2 members
[Finished in 254ms]