[파이썬] 딕셔너리를 활용한 CRUD구현
bts를 활용하여 dictionary 연습을 해보았다.
-노마드코더 복습
#insert deta
def insert_dict(a_list = {}, key = None, val = None):
if type(a_list) != dict:
print("Invalid type. You need to enter a dictionary type. you entered",type(a_list))
elif key == None or val == None:
print("Please enter a name and birth date.")
elif key in a_list:
print(f"{key} has been already inserted.")
else:
a_list[key] = val
print("Successful inserted!!")
select_dict(a_list, key)
#select data
def select_dict(a_list = {}, key = None):
if type(a_list) != dict:
print("Invalid type. You need to enter a dictionary type. you entered",type(a_list))
elif key == None:
print("Please enter data to search for.")
elif key not in a_list:
print(f"{key} is not found.")
else:
print(f"{key} : ",a_list[key])
#update data
def update_dict(a_list = {}, key = None, val = None):
if type(a_list) != dict:
print("Invalid type. You need to enter a dictionary type. you entered",type(a_list))
elif key == None or val == None:
print("Please enter name and birth date to update.")
elif key not in a_list:
print(f"{key} is not found and can't update." )
else:
a_list[key] = val
print("Successful updated!")
select_dict(a_list, key)
#delete data
def delete_dict(a_list = {}, key = None):
if type(a_list) != dict:
print("Invalid type. You need to enter a dictionary type. you entered",type(a_list))
elif key == None:
print("Please enter name to delete.")
elif key not in a_list:
print(f"{key} is not found and can't delete." )
else:
del a_list[key]
print("Successful deleted!")
select_dict(a_list, key)
bts = {
"jin" : 921204,
"suga" : 930309,
"J-hope" : 940218,
"RM" : 9409,
"jimin" : 951013,
"v" : 951230,
"abc" : 123456
}
print(bts)
print()
insert_dict("jungkook",970901)
insert_dict(bts,"jungkook")
insert_dict(bts,"jungkook",970901)
insert_dict(bts,"jungkook",970901)
print()
select_dict("v")
select_dict(bts)
select_dict(bts,"v")
select_dict(bts,"rm")
print()
update_dict("RM",940912)
update_dict(bts,"RM")
update_dict(bts,"RM",940912)
update_dict(bts,"rm",940912)
print()
delete_dict("abc")
delete_dict(bts)
delete_dict(bts,"abc")
delete_dict(bts,"abc")
print()
print(bts)
Author And Source
이 문제에 관하여([파이썬] 딕셔너리를 활용한 CRUD구현), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@natural_min/python06저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)