Skip to content

Commit cf2c10c

Browse files
committed
added csv_update.py
Signed-off-by: ABHIJIT SINHA <[email protected]>
1 parent 7121cc5 commit cf2c10c

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

core_concepts/test_dict.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ def main():
2424

2525
# look up: method 1
2626
try:
27-
dept = name_dept["no_key"] # throws exception when the key is not found
27+
dept = name_dept["alice"] # throws exception when the key is not found
2828
print(f"{dept}")
2929
except KeyError as e:
3030
print(f"error: {e}")
3131

3232
# look up: method 2
33-
if "key" in name_dept: # inefficient because it queries the dict twice
34-
dept = name_dept["no_key"]
33+
if "alice" in name_dept:
34+
dept = name_dept["alice"] # inefficient because it queries the dict twice
3535
print(f"{dept}")
3636

3737
# look up: method 3 (recommended)
38-
dept = name_dept.get("alice", "no_key") # provides the support for default value
38+
dept = name_dept.get("alice", "not found") # provides the support for default value
3939
print(f"{dept}")
4040

4141
# get all keys
@@ -51,7 +51,7 @@ def main():
5151

5252
# print the dict: method 2
5353
for key in name_dept: # __iter__() => iterates over the keys, similar to name_dept.keys()
54-
print(f"{key}: {name_dept[key]}")
54+
print(f"{key}: {name_dept[key]}") # does not occurs the key not found
5555

5656

5757
if __name__ == '__main__':

core_concepts/tuple_hands-on.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
3+
# author: greyshell
4+
# description: hands-on
5+
6+
7+
def main():
8+
# tuple: a finite ordered squence of values
9+
10+
# create tuple
11+
# tuple literals
12+
tup = (1, 2, "abc") # supports heterogeneous data types
13+
tup0 = 1, 2, 3 # also supports without first bracket, all values are packed into a single tuple
14+
print(type(tup0))
15+
16+
# build in tuple function
17+
tup2 = tuple("abc") # it accepts single argument of type iterable, this single parameter is optional
18+
tup3 = tuple() # creates an empty tuple
19+
20+
# create a tuple with exactly one element
21+
tup4 = (1,) # need to include a comma after first element
22+
23+
# tuple and string
24+
# similarities: finite length, indexing and slicing
25+
# differences: string can only contains chars but tuple can contain any kind of value
26+
values = (0, 1, 2, 3, 4)
27+
new_values = values[0:3] # returns a tuple
28+
print(new_values)
29+
30+
for n in new_values: # tuples are iterable
31+
print(n)
32+
33+
x, y = 10, 20 # example of tuple unpacking
34+
# LHS and RHS should be matched else it will raise ValueError
35+
# utility: returning multiple values from a function
36+
37+
# check the existance of a value using in operator
38+
if 3 in values:
39+
print("found")
40+
41+
# tuples are immutable like string and frozenset
42+
43+
t = (1, ['a', 'b'], 'word')
44+
t[1][0] = 'x' # changes the list value as it does not modify the 2nd obj - list address
45+
print(t)
46+
47+
48+
if __name__ == '__main__':
49+
main()
File renamed without changes.

0 commit comments

Comments
 (0)