Skip to content

Commit 46c8140

Browse files
committed
DotNetTutorialsUpdates1
1 parent 9c8bdc8 commit 46c8140

5 files changed

Lines changed: 353 additions & 3 deletions

File tree

Basic/04_lists.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
print(type(my_list))
2020
print(type(my_other_list))
2121

22+
# Creating a list using list() function
23+
r=range(0, 10)
24+
l=list(r)
25+
print(l)
26+
2227
# Acceso a elementos y búsqueda
2328

2429
print(my_other_list[0])
@@ -92,3 +97,18 @@
9297
my_list = "Hola Python"
9398
print(my_list)
9499
print(type(my_list))
100+
101+
names_list = ['John', 'James', 'Lily', 'Emily', 'Nina']
102+
print(names_list[::2])
103+
104+
# List Comprehensions
105+
my_list = [1, 2, 3, 4]
106+
my_list_2 = [ i*2 for i in my_list]
107+
print(my_list)
108+
print(my_list_2)
109+
110+
s=range(1, 20, 3)
111+
for i in s: #This loop is for knowing what is in s
112+
print(i)
113+
m=[x for x in s if x%2==0] #List comprehension
114+
print(m)

Basic/05_tuples.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
my_tuple = (35, 1.77, "Brais", "Moure", "Brais")
1111
my_other_tuple = (35, 60, 30)
1212

13+
# Parenthesis is optional for tuple
14+
one_more_tuple = 35, 60, 30
15+
1316
print(my_tuple)
1417
print(type(my_tuple))
18+
print(my_other_tuple)
19+
print(one_more_tuple)
1520

1621
# Acceso a elementos y búsqueda
1722

@@ -20,6 +25,7 @@
2025
# print(my_tuple[4]) IndexError
2126
# print(my_tuple[-6]) IndexError
2227

28+
2329
print(my_tuple.count("Brais"))
2430
print(my_tuple.index("Moure"))
2531
print(my_tuple.index("Brais"))
@@ -52,3 +58,54 @@
5258

5359
del my_tuple
5460
# print(my_tuple) NameError: name 'my_tuple' is not defined
61+
62+
# Operaciones
63+
64+
## Multiplication
65+
t1 = (10, 20, 30)
66+
t2 = t1 * 3
67+
print(t2)
68+
69+
## Longitud
70+
t = (10, 20, 30, 40)
71+
print(len(t))
72+
73+
## Count
74+
t = (10, 20, 10, 10, 20)
75+
print(t.count(10))
76+
77+
## Index
78+
t = (10, 20, 10, 10, 20)
79+
print(t.index(10))
80+
# print(t.index(30))# # ValueError
81+
82+
## Sort
83+
t = (40, 10, 30, 20)
84+
t1 = sorted(t)
85+
print(t)
86+
print(t1)
87+
88+
## Min y Max
89+
t = (40, 10, 30, 20)
90+
print(min(t)) # 10
91+
print(max(t)) # 40
92+
93+
# tuple packing
94+
a = 10
95+
b = 20
96+
c = 30
97+
d = 40
98+
t = a, b, c, d
99+
print(t)
100+
101+
# tuple unpacking
102+
t = (10, 20, 30, 40)
103+
a, b, c, d = t
104+
print("a=", a, "b=", b, " c=", c, "d=", d)
105+
106+
# Tuple comprehension
107+
t= ( x**2 for x in range(1,6))
108+
print(type(t))
109+
for x in t:
110+
print(x)
111+

Basic/06_sets.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
print(len(my_other_set))
1717

18+
#Creating a set using range function
19+
s=set(range(5))
20+
print(s)
21+
22+
1823
# Inserción
1924

2025
my_other_set.add("MoureDev")
@@ -25,6 +30,13 @@
2530

2631
print(my_other_set)
2732

33+
# Actualización
34+
s = {10,20,30}
35+
l = [40,50,60,10]
36+
s.update(l)
37+
print(s)
38+
39+
2840
# Búsqueda
2941

3042
print("Moure" in my_other_set)
@@ -55,3 +67,43 @@
5567
my_new_set = my_set.union(my_other_set)
5668
print(my_new_set.union(my_new_set).union(my_set).union({"JavaScript", "C#"}))
5769
print(my_new_set.difference(my_set))
70+
71+
x={10,20,30,40}
72+
y={30,40,50,60}
73+
print(x.symmetric_difference(y))
74+
print(x^y)
75+
76+
77+
s={10,20,30}
78+
s1=s.copy()
79+
print(s1)
80+
81+
s = {40,10,30,20}
82+
print(s)
83+
print(s.pop())
84+
print(s)
85+
86+
87+
s={10,20,30}
88+
s.discard(10)
89+
print(s)
90+
91+
s= {1, 2, 3, "Sharuk"}
92+
print(s)
93+
print(1 in s)
94+
print('S' in s)
95+
print(2 not in s)
96+
97+
s = {x*x for x in range(5)}
98+
print(s)
99+
100+
#remove duplicates elements in sets
101+
l=[10,20,30,10,20,40]
102+
s=set(l)
103+
print(s)
104+
105+
#frozen sets
106+
vowels = ('a', 'e', 'i', 'o', 'u')
107+
fSet = frozenset(vowels)
108+
print(fSet)
109+
print(type(fSet))

Basic/07_dicts.py

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
print(type(my_dict))
1111
print(type(my_other_dict))
1212

13-
my_other_dict = {"Nombre": "Brais",
14-
"Apellido": "Moure", "Edad": 35, 1: "Python"}
13+
my_other_dict = {"Nombre": "Brais", "Apellido": "Moure", "Edad": 35, 1: "Python"}
1514

1615
my_dict = {
1716
"Nombre": "Brais",
1817
"Apellido": "Moure",
1918
"Edad": 35,
2019
"Lenguajes": {"Python", "Swift", "Kotlin"},
21-
1: 1.77
20+
1: 1.77,
2221
}
2322

2423
print(my_other_dict)
@@ -27,6 +26,17 @@
2726
print(len(my_other_dict))
2827
print(len(my_dict))
2928

29+
d = dict()
30+
print(d)
31+
print(type(d))
32+
33+
d = dict({1: "Ramesh", 2: "Suresh", 3: "Mahesh"})
34+
print(d)
35+
36+
d = dict([(1, "Ramesh"), (2, "Arjun")])
37+
print(d)
38+
39+
3040
# Búsqueda
3141

3242
print(my_dict[1])
@@ -74,3 +84,42 @@
7484
print(list(dict.fromkeys(list(my_new_dict.values())).keys()))
7585
print(tuple(my_new_dict))
7686
print(set(my_new_dict))
87+
88+
d = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"}
89+
print("Before clearing dictionary: ", d)
90+
d.clear()
91+
print("After cleared entries in dictionary: ", d)
92+
93+
d = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"}
94+
print("Before delete dictionary: ", d)
95+
del d
96+
97+
d = dict([(1, "Ramesh"), (2, "Arjun")])
98+
print("length of dictionary is: ", len(d))
99+
100+
d = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"}
101+
print(d.get(1))
102+
print(d.get(100))
103+
104+
d = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"}
105+
print(d.get(1))
106+
print(d.get(100, "No key found"))
107+
108+
d = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"}
109+
print("Before pop:", d)
110+
d.pop(1)
111+
print("After pop:", d)
112+
113+
# This method removes an arbitrary item(key-value) from the dictionary and returns it.
114+
d = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"}
115+
print("Before popitem:", d)
116+
d.popitem()
117+
print("After popitem:", d)
118+
119+
d1 = {1: "Ramesh", 2: "Suresh", 3: "Mahesh"}
120+
d2 = d1.copy()
121+
print(d1)
122+
print(d2)
123+
124+
squares = {a: a * a for a in range(1, 6)}
125+
print(squares)

0 commit comments

Comments
 (0)