dictionary = {}
dictionary['apple'] = '사과'
# dictionary[key] = value로 dictionary에 data를 넣어줄 수 있다.
color = {'apple' : 'red', 'grape' : 'purple'}
for key, value in color.items(): # [('apple','red'),...]
print(key + "-" + value)
# apple-red
# grape-purple
import json
# JSON 파일을 읽고 문자열을 dictionary로 변환
def create_dict(filename):
with open(filename) as file:
json_string = file.read()
return json.loads(json_string)
# JSON 파일을 읽고 dictionary를 JSON 형태의 문자열로 반환
def create_json(dictionary, filename):
with open(filename, 'w') as file:
json_string = json.dumps(dictionary)
file.write(json_string)
num_set = {1, 3, 5, 7}
num_set.add(9) # {1, 3, 5, 7, 9}
num_set.update([3, 15, 4]) # {1, 3, 4, 5, 7, 9, 15}
num_set.remove(7) # {1, 3, 4, 5, 9, 15}
num_set.discard(13) # {1, 3, 4, 5, 9, 15}
set1 = {1, 3, 5 ,7}
set2 = {1, 3, 9, 27}
union = set1 | set2 # 합집합 {1, 3, 5, 7, 9, 27}
intersection = set1 & set2 # 교집합 {1, 3}
diff = set1 - set2 # 차집합 {5, 7}
xor = set1 ^ set2 # XOR {5, 7, 9, 27}
import csv
with open('movies.csv') as file:
reader = csv.reader(file, delimiter=',')
출처 : 엘리스 AI트랙 3기 11주차 수업