Home Coding Data Structure – Lists 04

Data Structure – Lists 04

0
Data Structure – Lists 04

# Lists methods and function 
# We will see some of the most used method and function for lists
# We will see: 
# sort(), append(), len(list), count(), insert(), pop(), 
# index(), remove(), reverse(), extend(), max(list),
# min(list), clear(), copy(), type(list)
#
# POP - REMOVE - LEN

# I'm a list. Yes, I'm the same old list 
list1 = ["Apple", "Banana", "Kiwi"]
# Guess my length!
len1 = len(list1)

# I want to be bigger!
list2 = list1.copy()
list2.extend(["Apple", "Watermelon", "Orange", "Pear", "Cherry", "Strawberry", "Nectarine", "Grape", "Mango"])
# Ok, now I'm big
len2 = len(list2)

list3 = list2.copy()
# What's append if I pop out something? Try to guess what I'm popping out
list4 = list3.pop(4)
# What will be the length of the list4? Do you remember from some days ago?
# I said that string is more or less like a list
len4 = len(list4)

list5 = list3.copy()
# And if I remove Apple? What's append?
list5.remove("Apple")
len5 = len(list3)


# copy www.AEC.codes
 OUT = (list1,len1),(list2,len2),(list4,len4),(list5,len5)