Dictionary Help! Extracting values and making a table

前端 未结 2 916
青春惊慌失措
青春惊慌失措 2021-01-28 05:31

Here\'s the question that I\'m supposed to code for:

Write the contract, docstring and implementation for a function showCast that takes a movie title and

2条回答
  •  别那么骄傲
    2021-01-28 06:33

    Maybe these snippets help you:

    Printing a table row

    def printRow(character, actor):
        print(character + (20 - len(character)) * ' ' + actor))
    

    Sorting the characters

    def getSortedTitleList(titleList):
        sortedList = []
        characters = sorted(titleList)
        for character in characters:
            sortedList.append((character, titleList[character]))
        return sortedList
    

    Note: I changed dict.keys().sort() to sorted(dict) to be compatible with Python 3.

提交回复
热议问题