-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinearsearchrevision.py
More file actions
86 lines (75 loc) · 1.67 KB
/
Copy pathlinearsearchrevision.py
File metadata and controls
86 lines (75 loc) · 1.67 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# str = "Hasnain"
# if 'a' in str:
# print("Found a")
# list1 = [10, 20, 30, 40]
# if 50 not in list1:
# print("50 not found")
# def linearSearch(arr, target):
# for i in range(len(arr)):
# if arr[i] == target:
# return i
# return -1
# print(linearSearch([1,2,3,4], 3))
# print(linearSearch(['a', 'b', 'c'], 'd'))
# print(linearSearch(["apple", "banana", "cherry"], "banana"))
# vowels = ['i', 'u', 'a', 'o', 'e']
# vowels.sort()
# print(vowels)
# x = [1,2,3,4,5]
# print(sorted(x))
# print("Reverse Sort")
# print(sorted(x, reverse=True))
# TUPLE
tup1 = (1, 2, 3, 4, 5)
# print(tup1)
# print(max(tup1))
# print(min(tup1))
# print(sum(tup1))
# print(len(tup1))
# print(sorted(tup1))
# print(sorted(tup1, reverse=True))
# print(tup1[2])
# print(tup1[1:-1])
# print(tup1.count(2))
# print(tup1.index(3))
# tup1[2] = 10 # Tuples are immutable
t1 = (10, 20, 30)
t2 = (40, 50, 60)
t3 = t1 + t2
# print(t3)
# t4 = t3 * 2
# print(t4)
# print(20 in t4)
# for v in tup1:
# print(v)
# print(t3[2:-1])
# print(t3[1:-2])
# import sys
# list = [1, 2, 3, 4, 5]
# tuple = (1, 2, 3, 4, 5)
# print("Size of list:", sys.getsizeof(list))
# print("Size of tuple:", sys.getsizeof(tuple))
myDict = {
"name": "Hasnain",
"age": 25,
"city": "Karachi"
}
if "name" in myDict:
print("Found 'name' in myDict")
if myDict.get("age") == 25:
print("Age is 25")
if myDict.get("country") is None:
print("Country key not found in myDict")
if "age" in myDict:
del myDict["age"]
d = {
"x": 10,
"y": 20,
"z": 30
}
for keys, values in d.items():
print(f"{keys} : {values}")
for key in d.keys():
print(key)
for value in d.values():
print(value)