Python For Og Lecture 32 33 34 35 Lists
Python For Og Lecture 32 33 34 35 Lists
Website - https://petroleumfromscratchin.wordpress.com/
LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch
YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw
Lists
# Syntax []
/
2/2/2021 Python for O&G Lecture 32, 33, 34, 35 - Lists 1 - Colaboratory
a = []
type(a)
list
type(pressure)
list
type(mud_wt)
list
type(list1)
list /
2/2/2021 Python for O&G Lecture 32, 33, 34, 35 - Lists 1 - Colaboratory
Lists Indexing
print(list1)
print(list1[0])
2500
print(list1[2])
Rajasthan
print(list1[4])
(5+4j)
print(list1[-1])
(5+4j)
List Slicing
curves[2:4:1]
['WPR', 'CPR']
curves[1:]
curves[:3:2]
['IPR', 'WPR']
# Reverse order
curves[::-1]
pressure[2] = 3000
print(pressure)
/
2/2/2021 Python for O&G Lecture 32, 33, 34, 35 - Lists 1 - Colaboratory
[1200, 2500, 3000]
# let's say we want to change all the elements instead of 1st element
1. append method
2. insert method
# append method
# let's say we are inputting a info of resrvoir in a list [location of the reservoir ,porosity, perm in md, resrervoir pressure]
res_1.append(3000)
/
2/2/2021 Python for O&G Lecture 32, 33, 34, 35 - Lists 1 - Colaboratory
print(res_1)
# insert method
# Allows us to add item in list based on index. means we can add the item wherever we want
# Syntax - list_name.insert(index where youu want to add, value which you want to add)
print(res_1)
a = [1, 2]
a.append(3)
[1, 2, 3]
a.append('hey')
print(a) /
2/2/2021 Python for O&G Lecture 32, 33, 34, 35 - Lists 1 - Colaboratory
[1, 2, 3, 'hey']
a.insert(2, 2.5)
print(a)
Concatenate lists
1. use of + operator
2. extend method
3. append method
# Use of + sign
b = [1,2]
c = [3, 4]
d = b + c
print(d)
[1, 2, 3, 4]
e = c + b
print(e)
[3, 4, 1, 2]
# extend method
/
2/2/2021 Python for O&G Lecture 32, 33, 34, 35 - Lists 1 - Colaboratory
x = [5, 6]
y = [7, 8]
x.extend(y)
print(x)
[5, 6, 7, 8]
x = [5, 6]
y = [7, 8]
x.append(y)
print(x)
Assignment 11
/
2/2/2021 Python for O&G Lecture 32, 33, 34, 35 - Lists 1 - Colaboratory
# But we know that barite and hametite aere density increasing additives, we want to remove them
pop method
# pop method
den_red.pop()
'Hametite'
print(den_red)
den_red.pop(2)
'Barite'
print(den_red)
del operator
# del operator
del den_inc[2]
print(den_inc)
remove method
# remove method
# til now in both the methds pop and del we removed the elements based on their index
# If we know the element's names and want to delete them by their name, we use remove method
trans_motion.remove('roll')
print(trans_motion)
trans_motion.pop()
'yaw'
print(trans_motion)
trans_motion.remove('pitch')
print(trans_motion)
/
2/2/2021 Python for O&G Lecture 32, 33, 34, 35 - Lists 1 - Colaboratory
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-70-3a554e4caf45> in <module>()
5
6
----> 7 trans_motion.remove('pitch', 'roll', 'yaw')
8
9
if 'Rockstar' in favs:
print('Rockstar is one of my fav movies')
else:
print('Rockstar is not there is list')
if 'Soul' in favs:
print('Soul is one of my fav movies')
else:
print('Soul is not there in list')
/
2/2/2021 Python for O&G Lecture 32, 33, 34, 35 - Lists 1 - Colaboratory