Professional Documents
Culture Documents
Python For Oil & Gas: # (Key: Value) - Dictionary
Python For Oil & Gas: # (Key: Value) - Dictionary
Website - https://petroleumfromscratchin.wordpress.com/
LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch
YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw
Sets
# {el1,el2} - set
# print(alpha)
type(alpha)
set
# unique items
alpha[1]
/
2/2/2021 Python for O&G Lecture 53, 54, 55: Sets - Colaboratory
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-da6fbe6453e6> in <module>()
7
8
----> 9 alpha[1]
10
11
# let's say we have list of all the lithology types encountered in an area where various wells have been drilled
lith = ['Sandstone', 'Shale', 'Sandstone', 'Limestone', 'Shale', 'Limestone', 'Coal Bed Seam', 'Sandstone', 'Coal Bed Seam', 'Limestone', 'Dolomite', 'Basement
lith_new = set(lith)
print(lith_new)
type(lith_new)
lith_2 = list(lith_new)
print(lith_2)
/
2/2/2021 Python for O&G Lecture 53, 54, 55: Sets - Colaboratory
type(lith_2)
set
set
Methods in sets
add method
stages_well.add('Development')
print(stages_well)
a = {1, 2, 5}
a.add(3, 4)
print(a)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-38-4264641dce06> in <module>()
4 a = {1, 2, 5}
5
----> 6 a.add(3, 4)
7
8 print(a)
/
2/2/2021 Python for O&G Lecture 53, 54, 55: Sets - Colaboratory
update method
print(a)
{1, 2, 5}
a.update([3, 4])
print(a)
{1, 2, 3, 4, 5}
a.update((6, 7, 8, 9))
print(a)
{1, 2, 3, 4, 5, 6, 7, 8, 9}
a.update('abc')
print(a)
a
b
c
# remove method
phi.remove('b')
/
2/2/2021 Python for O&G Lecture 53, 54, 55: Sets - Colaboratory
print(phi)
phi.add('c')
print(phi)
# discard method
phi.discard('c')
print(phi)
phi.discard(555)
clear method
phi.clear()
print(phi)
set()
copy method
/
2/2/2021 Python for O&G Lecture 53, 54, 55: Sets - Colaboratory
l = {1, 2, 3, 4, 5}
# union
n = l | m
print(n)
# intersection
k = l & m
print(k)
{2, 5}
Assignment 16
# I want two sets as result where the 1st set contains all the formations I have encountered in this area, 2nd set contains formations which are common to both