-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11115_Tuples_Conditional StatementsLesson.py
More file actions
212 lines (154 loc) · 6.22 KB
/
11115_Tuples_Conditional StatementsLesson.py
File metadata and controls
212 lines (154 loc) · 6.22 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
##################### TUPLE ################################
# my_tuple = ("hakankan")
# my_tuple2 = "hakankan"
# my_tuple = tuple("hakankan")
# print(my_tuple, type(my_tuple)) # tuple kelimeyi harflerine ayırıyor
# print(my_tuple2, type(my_tuple2))
# my_tuple = ("wakabayashi",) # tek başına eleman yapmak için
# my_tuple2 = "wakabayashi"
# my_tuple = tuple("wakabayashi")
# print(tuple(my_tuple2))
# print(my_tuple, type(my_tuple))
# print(my_tuple2)
my_tuple = ("wakabayashi")
my_tuple2 = "wakabayashi"
my_tuple = tuple("wakabayashi")
print(my_tuple, type(my_tuple), sep="\n")
print(my_tuple2)
# my_tuple = (1, 2, 3, 4, 567, 7, 863)
# my_list = list(my_tuple)
# print(my_tuple, type(my_tuple), sep="\n")
# print(my_list, type(my_list), sep="\n")
# my_tuple = (1, 2, 3, 4, 567, 7, 863)
# print(my_tuple[3])
# # print(my_tuple[3:5]) # start stop var bu komutta da
# my_tuple = (1, 2, 3, 4, 567, 7, 863)
# my_tuple[3] = 5 # tuple'a ekleme yapamıyoruz, fakat liste olsaydı yapabilirdik ama tuple olduğu için yapamıyoruz
# print(my_tuple) #
# my_tuple = (1, 2, 3, 4, 567, 7, 863)
# my_list = list(my_tuple)
# my_list[4] = 5 # liste hali ile olabiliyor
# print(my_list)
# sehirler = ["Istanbul", "Izmir", "Ankara", "Van", "Erzurum", "Sivas", "Gonya", "Ssinop", "Muğla", "Gaziantep"]
# print(sehirler)
# sehirler_tuple = tuple(sehirler)
# sehirler[9] = "Yozgat" # [10] yazılırsa, "list assignment index out of range" hatası alırız
# print(sehirler)
# # sehirler[0] = "Muş" # 'tuple' object does not support item assignment" hatası verir
# DICTIONARIES ####################################################################################################
# {key1 : value1, key2 : value2}
# {}
# dict()
# first_dict1 = {"cola" : 25, "ekmek" : 5, "makarna" : 5}
# first_dict2 = dict(kola = 5, ekmek =4, makarna = 5)
# print(first_dict1)
# print(first_dict2)
# state_capitals = { "Ankara" : "Little Rock",
# "Colorado" : "Denver",
# "California" : "Sacramento",
# "Geogia" : "Atlanta"
# }
# #state_capitals = ["Virgina" : "Richmond"] # yanlış
# print(state_capitals["Atlanta"]) # atlanta değerini döndürüyor
# print(state_capitals["Atlanta"])
# state_capitals = { "Ankara" : "Little Rock",
# "Colorado" : "Denver",
# "California" : "Sacramento",
# "Geogia" : "Atlanta"
# }
# state_capitals["Virgina"] = "Richmond"
# print(state_capitals)
# mix_values = {"animal": ("dog", "cat"), #tuple
# "planet": ["Neptun", "Pluton", "Jupyter"], #liste
# "number": 40, #integer
# "pi": 3.14, #float
# "is_good": False} #boolean
# mix_keys = {22 : "number",
# 3.14 :"float",
# True: "boolean",
# "key": "string"}
# my_dictionary = dict(animal= ("dog", "cat"), planet = ["Neptun", "Pluton", "Saturn"], number = 65)
# print(my_dictionary)
###### Main Operations With Dicts #################################
# items, keys, values
# mix_values = {"animal": ("dog", "cat"), #tuple
# "planet": ["Neptun", "Pluton", "Jupyter"], #liste
# "number": 40, #integer
# "pi": 3.14, #float
# "is_good": False} #boolean
# mix_keys = {22 : "number",
# 3.14 :"float",
# True: "boolean",
# "key": "string"}
# print(mix_values.items(), "\n") # hepsini gösteriyor
# print(mix_values.keys(), "\n") # "\n" silinebiliriz de yukarıdaki için de gerçerli
# print(mix_values.values())
# mix_values = {"animal": ("dog", "cat"), #tuple
# "planet": ["Neptun", "Pluton", "Jupyter"], #liste
# "number": 40, #integer
# "pi": 3.14, #float
# "is_good": False} #boolean
# mix_keys = {22 : "number",
# 3.14 :"float",
# True: "boolean",
# "key": "string"}
# print(mix_values.items(), "\n") # hepsini gösteriyor
# print(mix_values.keys(), "\n") # "\n" silinebiliriz de yukarıdaki için de gerçerli
# print(mix_values.values(), "\n")
# mix_values.update({"is_bad" : True}) # value ekleme
# print(mix_values)
# del mix_values["is_good"] # silme işlemi
# print(mix_values)
############## Nested Dictionaries #######################################
# ayrımlar ve dict üzerinden yapılıyor
# school_records={
# 'personal_info':
# {'kid':{'tom':{'class':'intermediate', 'age':10},
# 'sue':{'class':'elemantary', 'age':8}
# },
# 'teen':{'joseph':{'class':'college', 'age':19},
# 'marry':{'class':'high school', 'age':16}
# },
# },
# 'grades_info':
# {'kid':{'tom':{'math':88, 'speech':69},
# 'sue':{'math':90, 'speech':81}
# },
# 'teen':{'joseph':{'coding':80, 'math':89},
# 'marry':{'coding':70, 'math':96}
# },
# }
# }
# print(school_records["grades_info"]["kid"]["sue"]["speech"])
# family = {
# "erkek" : {
# "baba" : {"yas" : 40, "meslek" : "eyt emeklisi" },
# "kardes" : {"yas" : 22, "meslek" : "ogrenci"}
# },
# "kadin" : {
# "anne" : {"yas" : 40, "meslek" : "emekli albay"},
# "abla" : {"yas" : 27, "meslek" : "influencer"}
# }
# }
# print(family["kadin"]["anne"]["meslek"])
############# set ##############################
# setler unordered, dict order
# set_1 = {'red', 'blue', 'pink', 'red'}
# colors = 'red', 'blue', 'pink', 'red'
# set_2 = set(colors)
# print(type(set_1)) # her defasında farklı değerleri verir
# print(set_2)
# flower_list = ["rose", "orchid", "cactus", "ginger", "rose", "tulip"]
# flower_set = set(flower_list)
# print(flower_list)
# print(flower_set) # tekrarlı elemanı bir kere yazıyor
# a = set("aaAngara")
# b = set("Istanbul")
# c = set("Izmir")
# d = set("afyonkarahisar")
# #rint(a, b, sep = "\n") # print(a), print(b)
# print(a.difference(b)) # == print(a - b) farkı
# print(b.difference(a, c, d)) # == print(b - a, c, d)
# print(a.union(b)) # == print(a I b) birleşim
# print(b.union(a)) # == print(b I a)
# print(a.intersection(b)) # == print(a & b) kesişimi