top of page

Lists (Arrays)

#---- Lists (Arrays) -----
# They have multiple types of lists / arrays
# Static Lists, Muti-Dimesional, Variable Arrays 
# Some are unchangable some are as defined by {}, [], ()
# ---Dynamic Size---:
# Lists can grow or shrink in size as needed. You
# don't have to pre-allocate memory for them.
# ---Heterogeneous Elements---:
# Lists can store elements of different data types, unlike arrays in
# many other languages which require elements to be of the same type.


print('------------------------Build List --------------------------')
#--Build List -- Display Details --|
mylist=['scott',24,float(2.35)]
print(24 in mylist) # Verify item in List
print('List Length') # Amount of Items in List
print(len(mylist)) # Prints the List 

print('------------------------While Loop Display--------------------------')
#--Display List with While Loop--|
x=0
while x < 3:
    print('Array Counter',x)
    print(mylist[x])
    x=x+1

print('------------------------ Multi Inline Variable Assignment --------------------------')
#--Define Some Variables--
print('Display multiple assigned values')
myvar_a, myvar_b, myvar_c = 2,3,4
print(myvar_a)
print(myvar_b)
print(myvar_c)

print('------------------------Set List--------------------------')
#--Class Set List-- Unique Values / no [2] Access
# Duplicate values are automatically removed upon insertion.
var_set_list ={'Scott','Joe','Sam','Scott',2,2}
print('Scott' in var_set_list)
print(type(var_set_list))
#--Loop Proves Duplicates are Removed 
for var in var_set_list:
    print(var)

print('------------Value Pairs Dictionay List--------------')
#-- Build Object Style List / Array / Key Value Pairs / Hash--
myobj ={
    'Computer Name':'Server01',
    'OS':'Windows Server 2022'
}
print("Select Specific Item in Object / Array")
print(myobj['OS'])

print('------------------------For Loop--------------------------')
#--Display Using Foreach Loop---
print('Foreach Style Loop')
for item in mylist:
    print(item)

 


print('------------------------List Append--------------------------')
#--Appends the List--
mylist.append(234)
#--Foreach Loop--
print('Foreach Style Loop')
for item in mylist:
    print(item)

 


print('------------------------List Extend--------------------------')
#--Extend List with another List--
list_b = ['Scott','Weston','Head']
#--Extend List--
mylist.extend(list_b)
#--Foreach Loop--
print('Foreach Style Loop')
for item in mylist:
    print(item)
print('List Length')
print(len(mylist))

print('------------------------Static Tuple List--------------------------')

#--Static List 'tuple'() Types--

var_static_list = (2,3,4)

#var_static_list.append(5)-- Fails Due to Static List

print(var_static_list)

bottom of page