while True:

プログラミング演習(備瀬 竜馬)

第12回

小問番号はコメント(#)を参照
# 12_A_1
japanese = ["日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"]
english = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
dic = {ja: en for ja, en in zip(japanese, english)}
print(dic)


# 12_A_2
phone_number = {"田中": 1110, "佐藤": 1111, "横山": 1112}
phone_number["田中"] = 1113
phone_number["伊藤"] = 1114
del(phone_number["佐藤"])
print(phone_number)


# 12_B_1
dic = {0: [], 1: [], 2: [], 3: [], 4: []}
for x in range(100):
    num = x + 1
    for y in range(5):
        if num % 5 == y:
            dic[y].append(num)
print(dic)


# 12_B_2
sentence = "nvcioanfiaewrfnaerilfnsdjiafdsnjai"
chars = list(sentence)
dic = {}
for c in chars:
    if c in dic.keys():
        dic[c] += 1
    else:
        dic[c] = 1
print(dic)


# 12_C_1
sentence = """
London Bridge is falling down,
Falling down,
Falling down.
London Bridge is falling down,
My fair lady.
Take a key and lock her up,
Lock her up,
Lock her up.
Take a key and lock her up,
My fair lady.
How will we build it up,
Build it up,
Build it up?
How will we build it up,
My fair lady?
Build it up with silver and gold,
Silver and gold,
Silver and gold.
Build it up with silver and gold,
My fair lady.
Gold and silver I have none,
I have none,
I have none.
Gold and silver I have none,
My fair lady.
Build it up with needles and pins,
Needles and pins,
Needles and pins.
Build it up with needles and pins,
My fair lady.
Pins and needles bend and break,
Bend and break,
Page 3 of 3
Bend and break.
Pins and needles bend and break,
My fair lady.
Build it up with wood and clay,
Wood and clay,
Wood and clay.
Build it up with wood and clay,
My fair lady.
Wood and clay will wash away,
Wash away,
Wash away.
Wood and clay will wash away,
My fair lady.
Build it up with stone so strong,
Stone so strong,
Stone so strong.
Build it up with stone so strong,
My fair lady.
Stone so strong will last so long,
Last so long,
Last so long.
Stone so strong will last so long,
My fair lady."""
dic = {}
words = sentence.split()
words = [c.lower() for c in words]
words = [d.rstrip(".,!?") for d in words]
for w in words:
    if w in dic.keys(): # すでに出現
        dic[w] += 1
    else: # 初登場
        dic[w] = 1
print(dic)
  
ページのトップへ戻る