Професионална програма
Loading...
+ Нов въпрос
MartinBG avatar MartinBG 3910 Точки

Тази част т условието не е изпълнена:

Also the final input line will be "{bandName}" and you have to print all members for this band in insertion order.

Това е леко модифицирано решение (премахнал съм и някои излишни повторения на код), което взема 100/100:

info = input()
collection_band_time = {}
collection_band_members = {}
total_time = 0

while info != 'start of concert':
    args = info.split('; ')
    command = args[0]
    brand_name = args[1]

    if brand_name not in collection_band_time:
        collection_band_members[brand_name] = []
        collection_band_time[brand_name] = {}
        collection_band_time[brand_name]['time'] = 0

    if command == 'Add':
        members = args[2]
        member = members.split(', ')

        for n in member:
            if n not in collection_band_members[brand_name]:
                collection_band_members[brand_name].append(n)

    elif command == 'Play':
        time = int(args[2])
        total_time += time

        collection_band_time[brand_name]['time'] += time

    info = input()

print(f'Total time: {total_time}')
collection_band_time = dict(sorted(collection_band_time.items(), key=lambda x: (-x[1]['time'], x[0])))

for key, value in collection_band_time.items():
    print(f'{key} -> {value["time"]}')

band_name = input()
print(band_name)

for band_member in collection_band_members[band_name]:
    print(f'=> {band_member}')

 

1
Different avatar Different 1 Точки

Благодаря!

1