Professional Documents
Culture Documents
Website - https://petroleumfromscratchin.wordpress.com/
LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch
YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw
count method
sort method
sorting function
clear method
split method
join method
count method /
2/2/2021 Python for O&G Lecture 36, 37, 38, 39, 40: Lists Part 2 - Colaboratory
# count method
phi = [0.2, 0.3, 0.25, 0.4, 0.2, 0.35, 0.31, 0.30, 0.2]
phi.count(0.2)
phi.count(0.30)
alpha = ['a', 'b', 'f', 'o', 65, 'b', 'b', 'c', 'a']
alpha.count(65)
sort method
# sort method
# list_name.sort()
phi = [0.2, 0.3, 0.25, 0.4, 0.2, 0.35, 0.31, 0.30, 0.2]
/
2/2/2021 Python for O&G Lecture 36, 37, 38, 39, 40: Lists Part 2 - Colaboratory
phi.sort()
print(phi)
alpha.sort()
print(alpha)
sorting function
# sorting function
sorted(num)
print(num)
clear method
# clear method
# syntax - list_name.clear()
print(num)
num.clear()
print(num)
[]
copy method
# copy method
abc_new = abc.copy() /
2/2/2021 Python for O&G Lecture 36, 37, 38, 39, 40: Lists Part 2 - Colaboratory
print(abc_new)
split method
# split method
# for example ask first name and last name of user. store them in two different variables
first, last = input('Please enter your first name and last name: ').split()
Please enter your first name and last name: Divyansh Sethi
print(first)
print(last)
Divyansh
Sethi
full_name = input('Please enter your first name and last name: ').split()
Please enter your first name and last name: Divyansh Lokesh Sethi
print(full_name)
join method
(', ').join(full_name)
Loops in list
phi = [0.2, 0.3, 0.25, 0.4, 0.2, 0.35, 0.31, 0.3, 0.2]
len(phi)
i = 0 /
2/2/2021 Python for O&G Lecture 36, 37, 38, 39, 40: Lists Part 2 - Colaboratory
0.2
0.3
0.25
0.4
0.2
0.35
0.31
0.3
0.2
phi = [0.2, 0.3, 0.25, 0.4, 0.2, 0.35, 0.31, 0.3, 0.2]
for i in phi:
print(i)
0.2
0.3
0.25
0.4
0.2
0.35
0.31
0.3
0.2
# [por, perm, payzone height] - This is how a list for one reservoir will look like
info = [[0.2, 25, 40], [0.15, 30, 55], [0.30, 35, 60]]
len(info)
info = [[0.2, 25, 40], [0.15, 30, 55], [0.30, 35, 60]]
info[1]
info[0][1]
25
info[2][2]
60
info = [[0.2, 25, 40], [0.15, 30, 55], [0.30, 35, 60]]
for i in info:
print(i)
for i in info: # values of i - [0.2, 25, 40], [0.15, 30, 55], [0.3, 35, 60]
for j in i:
print(j)
0.2
25
40
0.15
30
55
0.3
35
60
ab = list(range(1, 100))
print(ab)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 4
/
even = list(range(2 14 2))
2/2/2021 Python for O&G Lecture 36, 37, 38, 39, 40: Lists Part 2 - Colaboratory
even = list(range(2, 14, 2))
print(even)
Code Text
# I want to prepare a function which converts all the items of list into negative
def negative(a):
neg_items = [] # -12, -1, .....-20
for i in a: # a = nums = [12, 1, 45, 23, 54, 20] i = 12, 1
neg_items.append(-i)
return neg_items
negative(nums)
negative(jkl)
/
2/2/2021 Python for O&G Lecture 36, 37, 38, 39, 40: Lists Part 2 - Colaboratory
Excercises
Exercise 1
# create a function such that we get a output as a list which shows values as Even or odd
def even_odd(b):
EoO = []
for i in b: # 10, 14, 20, 25.........45
if i%2 == 0:
EoO.append('Even')
else:
EoO.append('Odd')
return EoO
even_odd(perm)
ev_od = []
for i in perm_2:
if i%2 == 0:
ev_od.append('Even')
else:
ev_od.append('Odd')
print(ev_od)
even_odd(perm_2)
Excercise 2
# You have to crate a function which returns us the list with these porosities values in fraction
def fraction(p):
por_frac = []
for i in p:
por_frac.append(i/100)
return por_frac
fraction(por)
fraction(por_2)
Assignment 12
# mak a function that returns us the list of sat of oil for each saturation of water
print(s_w)
/
def saturation oil(a):
2/2/2021 Python for O&G Lecture 36, 37, 38, 39, 40: Lists Part 2 - Colaboratory
def saturation_oil(a):
s_o = []
for i in a:
s_o.append(100-i-10)
return s_o
saturation_oil(s_w)
Assignment 13
# mud densities filter them into lists i.e. one for mud wt less than 12 and other for more than 12.
def filter(k):
less = []
more = []
for i in k:
if i <= 12:
less.append(i)
else:
more.append(i)
return [less, more]
filter(mud_wt)
/
2/2/2021 Python for O&G Lecture 36, 37, 38, 39, 40: Lists Part 2 - Colaboratory