List tutorial

PHOTO EMBED

Sat Jan 07 2023 05:52:51 GMT+0000 (Coordinated Universal Time)

Saved by @Shaghaf_2000 #python

# Basics of lists:
""""
monash = ["ENG1013", "ENG1012", "ENG1021", "MTH1020", [15082000, 'Shaghaf']]   
whenever I want to put a string within a list, I have to put qoutation marks "".
the last item in the list is a list inside another list, I just have to put a square brackets to refer to the list []

another way to print the last item in the list is by using this syntax 
print(monash[-1])

لو كنت ابغى البرنمج يطبع لي العناصر كلها من الأول الى الأخير بدون  ما يتضمن الأخير
print(monash[0:4])

لو كنت حابة اطبع من عند عنصر معين الى نهاية القائمة
print(monash[3:]) 3 العنصر اللي ببدا منه
print(monash[1:])

"""

# لو كنت حابة اغير العنصر الأول
""""
monash[1]= 'ENG1014'
print(monash[1])
monash[0] = 'ENG1005'
print(monash[0])
monash[2] = 'ENG1011'
monash[3] = 'BMS1021'
print(monash)
"""
monash = ["ENG1013","ENG1013", "ENG1012", "ENG1021", "MTH1020", 'Shaghaf']  
rmit = ["Math", 'Physics Basics', 'Introduction to Engineering', 15, True]
# to print out the to lists at the same time use this symtax:
# print(monash, rmit)
""""
functions in lists:
in order to join these two lists in one list, there are 3 ways:

1.  use .extend() function 
the_ma_infunction.extend(the_function_that_you_it_to_be_added)
then print out the main function
monash.extend(rmit)
print(monash)

2. use this syntax: 
monash += rmit
print(monash)

3. use this synatx:
monash = monash + rmit
print(monash)

"""
# to add another item into the list use .append(), then you must print out the new list
# هذه الطريقة تضيف عنصر جديد في نهاية القائمة فقط 
"""
monash.append("ENG111")
print(monash)
monash.append("ENG2000")
print(monash)
monash.append("ENG3000")
 print(monash)

"""

# insert function: تستخد لأضافة عنصر جديد في مكان معين في القائمة 
"""
monash.insert(index location, 'new item')
monaash.insert(1, ENG1015)
print(monash)

"""
 # to remove an item from a list, there are 2 ways:
""""
1. using .remove() function: in the bracket I have to write the the string itself not the index
monash.remove("ENG1021")
print(monash)
2. using .pop() function 
print(monash)

""" 
 # to delete everything inside a list: follow this syntax
"""
monash.clear()
print(monash)
RMIT.clear()
print(rmit)

    """
# In order to delete the last item only: use .pop()
""""
monash.pop()
print(monash)

"""
# Also in pop function I can save what has been poped:
"""
last_item_popped = monash.pop()
print(last_item_popped)

"""
# if I wanna know the items that are duplicated within a list use:
"""
print(monash.count("ENG1013"))
print(listname.count("the item required to be counted"))

"""
# in lists, we can organize the list using .sort() function:
# alphabetically when it comes to strings and from smallest number to the biggest
content_copyCOPY