Learning Journal Unit 6
Learning Journal Unit 6
Learning Journal Unit 6
Wish you be fine. I tried my best to do all parts correctly. Since people are not free
from mistakes, please let me know if I made any mistakes.
Part one
I made a series of names, then I want to try split with name, by using split we can
break a string into words.
name=name.split()
print(name)
There are different ways for deleting the elements from a list, I will use del, pop and
remove metod:
#del method
del name[4]
print(name)
Output:
#pop method
name1=name.pop(3)
print(name)
name.remove('Maliha')
print(name)
Sort list
By using sort we can arrange the elements of a list from low to high.
name.sort()
print(name)
As there are many ways for deleting of elements from a list, there are also different
ways for adding elements into a list, I will use the append, extend and + operator in
Python to add words at the end of our list, which I add Bahram, Safa and Razia to
my list.
# append method
name.append('Bahram')
print(name)
# extent method
name2=['Safa']
name.extend(name2)
print(name)
Output: ['Frozan', 'Nasiba', 'Bahram', 'Safa']
# +method
name3=['Razia']
name+=name3
print(name)
# using join
delimiter=','
name=delimiter.join(name)
print(name)
Output: Frozan,Maliha,Ahmad,Shadab,Razia
Part 2
#nested list
f=['going to study']
a=[f,'tonight']
print(a)
Output: [['going to study'], 'tonight']
Comment: A list within another list is nested (Downey, 2015). Inside the output list is two list.
Frist is (going to study) and second is (tonight).
#the * operator
w=['frozan']
print(w*4)
Output: ['frozan', 'frozan', 'frozan', 'frozan']
Comment: The * operator repeats a list a given number of times (Downey, 2015). In this case
frozan repeated four times.
#list slices
s=['frozan', 'sakina', 'maliha', 'nasiba']
s[2:]=['hasani']
print(s)
Output: ['frozan', 'sakina', 'hasani']
Comment: A segment of a list is known as slices list, we can add or remove element from it. I
added hasani instead of nasiba.
#the += operator
fr=['frozan sakina nasiba']
fr1=['maliha']
fr+=fr1
print(fr)
Output: ['frozan sakina nasiba', 'maliha']
Comment: The += operator provides a short way to update a variable (Downey, 2015). I add
maliha in my list.
# list fliter
l=[13, 20, 30, 33, 40, 46, 50]
result=list(filter(lambda x:(x%5==0),l))
print(result)
Output: [20, 30, 40, 50]
Comment: filter selects some of the elements and filters out the others (Downey, 2015). Output
shows that it filtered just those number that divisible by 5.
# A list operation that is legal but does the "wrong" thing, and not what the programmer expects
g=[3, 4, 5]
g= g.extend(6)
print(g)
Output: error
Comment: it expected that add 6 at the list, but it won’t. Instead the output shows error.
Reference: