# ArrayListDemo.py Copyright (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-05-20 File created. # 2022-12-18 Converted to Python 3. # A better name for this program might be ListDemo.py # This program works in the same way as ArrayListDemo.java def print_list( given_list ) : print( "\n" ) for list_element in given_list : print( "%5s" % list_element, end=" " ) # The main program begins. list_of_integers = [] list_of_integers.append( 202 ) list_of_integers.append( 101 ) list_of_integers.append( 505 ) list_of_integers.append( 404 ) print( "\n Value 404 has index: %d" % list_of_integers.index( 404 ), end="" ) print_list( list_of_integers ) list_of_integers.insert( 2, 999 ) list_of_integers.insert( 2, 888 ) print_list( list_of_integers ) list_of_integers.pop( 4 ) # removes the element that has index 4 print_list( list_of_integers ) list_of_integers.remove( 888 ) # removes the value 888 print_list( list_of_integers ) another_list = [] another_list.append( 777 ) another_list.append( 666 ) print_list( another_list ) list_of_integers = list_of_integers + another_list print_list( list_of_integers ) list_of_integers[ 3 ] = list_of_integers[ 3 ] + 7 print_list( list_of_integers ) print( "" ) # Note that a simpler way to print a list is to write # print list_of_integers