import random
names = [“Taro”, “Jiro”, “Saburo”, “Shiro”, “Goro”]
names = list(set(names))
winners = random.sample(names, 3)
print(winners)
import random
names = [“Taro”, “Jiro”, “Saburo”, “Shiro”, “Goro”]
names = list(set(names))
winners = random.sample(names, 3)
print(winners)
from random import randint
n = randint(1,6)
print(n)
scores = [
{“name”: “Taro”, “math”: 70, “english”: 82},
{“name”: “Jiro”, “math”: 67, “english”: 61},
{“name”: “Saburo”, “math”: 81, “english”: 58},
]
print(“Name Math English”)
print(“——– ——– ——–“)
scores.sort(key=lambda score: score[“math”], reverse=True)
for score in scores:
for value in score.values():
print(f”{value:8} “, end=””)
print()
scores = [
{“name”: “Taro”, “math”: 70, “english”: 82},
{“name”: “Jiro”, “math”: 67, “english”: 61},
{“name”: “Saburo”, “math”: 81, “english”: 58},
]
print(“Name Math English”)
print(“——– ——– ——–“)
for score in scores:
for value in score.values():
print(f”{value:8}”, end=””)
print()
keys = [“math”, “english”, “physics”]
values = [62, 91, 84]
scores = {}
for key, value in zip(keys, values):
scores[key] = value
scores ={key: value for key, value in zip(keys, values)}
print(scores)
nums = [10, 20, 30]
nums_bak = nums.copy()
nums[0] = 100
print(nums)
print(nums_bak)
eng_members = [“Taro”, “Jiro”, “Saburo”]
math_members = [“Jiro”, “Saburo”, “Shiro”]
eng_members = set(eng_members)
math_members = set(math_members)
print(eng_members – math_members)
print(math_members – eng_members)
members = {“Taro”, “Jiro”, “Saburo”}
frozen_members = frozenset(members)
frozen_members.add(“Goro”)
scores = {“math”: 62, “english”: 91, “physics”: 84}
for key, value in scores.items():
print(f”{key:8}{value:3}”)
scores = [62, 91, 84]
scores = {“math”: 62, “english”: 91, “physics”: 84}
popped_value = scores.pop(“english”)
print(scores)
print(popped_value)