관련된 정보들을 몇 개의 그룹으로 묶어줄 수 있음.
key : 단어 / value : 정의
{key : value}
programming_dictionary = {
"Bug": "An error in a program that prevents the program from running as expected.",
"Function": "A piece of code that you can easily call over and over again."
}
print(programming_dictionary["Bug"])
programming_dictionary["Loop"] = "The action of doing something over and over again."
empty_dictionary = {}
programming_dictionary = {}
print(programming_dictionary)
programming_dictionary["Bug"] = "A moth in your computer."
for thing in programming dictionary:
print(thing)
print(programming_dictionary[Key])
student_scores = {
"Harry": 81,
"Ron": 78,
"Hermione": 99,
"Draco": 74,
"Neville": 62,
}
student_grades = {}
for key in student_scores:
score = student_scores[key]
if score > 90:
student_grades[key] = "Outstanding"
elif score > 80 :
student_grades[key] = "Exceeds Expectations"
elif score > 70 :
student_grades[key] = "Acceptable"
else:
student_grades[key] = "Fail"
print(student_grades)
#Nesting
capitals = {
"France": "Paris",
"Germany": "Berlin",
}
travel_log = {
"France": ["Paris", "Lille", "Dijon"],
"Germany": ["Berlin", "Hamburg", "Stuttgart"],
}
travel_log = {
"France": {"cities_visited": ["Paris", "Lille", "Dijon"], "total_visits": 12},
"Germany": {"cities_visited": ["Berlin", "Hamburg", "Stuttgart"], "total_visits": 5},
}
travel_log = [
{
"country": "France",
"cities_visited": ["Paris", "Lille", "Dijon"],
"total_visits": 12,
},
{
"country": "Germany",
"cities_visited": ["Berlin", "Hamburg", "Stuttgart"],
"total_visits": 5,
},
]
travel_log = [
{
"country": "France",
"visits": 12,
"cities": ["Paris", "Lille", "Dijon"]
},
{
"country": "Germany",
"visits": 5,
"cities": ["Berlin", "Hamburg", "Stuttgart"]
},
]
def add_new_country(country_visited, times_visited, cities_visited):
new_country = {}
new_country["country"] = country_visited
new_country["visits"] = times_visited
new_country["cities"] = cities_visited
travel_log.append(new_country)
add_new_country("Russia", 2, ["Moscow", "Saint Petersburg"])
print(travel_log)
from replit import clear
from art import logo
print(logo)
dic = {}
bid_continue = True
while bid_continue:
name = input("What is your name?: ")
bid_price = int(input("What is your bid?: $"))
dic[name] = bid_price
ans = input("Are there any other bidders? 'yes' or 'no'.: ").lower()
if ans == "yes":
clear()
elif ans == "no":
bid_continue = False
max_bid = max(dic.values())
winner = max(dic, key = dic.get)
print(f"The winner is {winner},the bid is ${max_bid}.")
else:
print("You put wrong answer.")
from replit import clear
from art import logo
print(logo)
bids = {}
bidding_finished = False
def find_highest_bidder(bidding_record):
highest_bid = 0
winner = ""
# bidding_record = {"Angela": 123, "James": 321}
for bidder in bidding_record:
bid_amount = bidding_record[bidder]
if bid_amount > highest_bid:
highest_bid = bid_amount
winner = bidder
print(f"The winner is {winner} with a bid of ${highest_bid}")
while not bidding_finished:
name = input("What is your name?: ")
price = int(input("What is your bid?: $"))
bids[name] = price
should_continue = input("Are there any other bidders? Type 'yes or 'no'.\n")
if should_continue == "no":
bidding_finished = True
find_highest_bidder(bids)
elif should_continue == "yes":
clear()