forked from AmGhGitHub/SAGA_Python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpy_lesson12.py
More file actions
49 lines (41 loc) · 2 KB
/
py_lesson12.py
File metadata and controls
49 lines (41 loc) · 2 KB
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
41
42
43
44
45
46
47
48
49
## without having a dictionary, you should make a note what each value
## presents in a list
# rock_properties = ['sand-stone', 125.3, 0.14, 0.21] # elements:rock_type, perm, poro, sw
## define a dictionary withn key:value pairs inside {}
rock_prop = {'type': 'sand-stone', 'perm': 125.3, 'poro': 0.14, 'sw': 0.21}
# print(type(rock_prop))
## another method of defining a dictionary is to use dict constructor key=value pair
# rock_prop_2 = dict(_type='sand-stone', perm=125.3, poro=0.14, sw=0.21)
#?? why I didn't use type and used _type instead
## to get the values for a key use curly braces or get method
# permeability = rock_prop['perm'] # if the key doesn't exist, and exception error will be thrown
# porosity = rock_prop.get('poro') # get method will return None if the key doesn't exist
# print(f"Permeability={permeability}\nPorosity={porosity}") # \n is of the escape characters in Python
'''
Escape Characters
To insert characters that are illegal in a string, use an escape character.
An escape character is a backslash \ followed by the character you want to insert.
A few common escape characters are below:
\' Single Quote
\\ Backslash
\n New Line
\t Tab
'''
## to get the values of a dictionary
prop_values = rock_prop.values()
# print(list(prop_values)) # we can use list function to convert result into list
## to get the values of a dictionary
prop_items = rock_prop.items()
prop_items_list = list(prop_items)
print(f"List of items is 'rock_prop' dictionary: {prop_items_list}")
# print(list(prop_values)) # we can use list function to convert result into list of tuple
## A tuple is an immutable(unchangable) sequence of Python objects.
## Tuples are sequences, just like lists.
## The differences:
## the tuples cannot be changed unlike lists
## tuples use parentheses, whereas lists use square brackets.
sws = (0.2, 0.3, .25)
print(f"Type of sws:{type(sws)}")
# perms_tuple = tuple([102.5, 123, 56.01])
# for perm in perms_tuple:
# print(perm)