如何在python中按字母顺序打印排序的多个句子?

我在获取输出时遇到问题。我收到的句子无序输出,需要按字母顺序对它们进行排序。


import sys

import os

from urllib.request import Request

from urllib.request import urlopen

from urllib.error import URLError

import json



def  getMovieTitles(variable):

    # variable = raw_input()

    var = str(variable)


    for i in range(0, 10):

        page = str(1)

        url = "https://jsonmock.hackerrank.com/api/movies/search/?Title=%s&page=%s" % (var, page)


# while(int(page)<int(page)+1):

        response = urlopen(url).read().decode('UTF-8')

        data = json.loads(response)

# response2 = urllib2.urlopen(url2)

        # data = json.loads(response.content.decode('utf-8'))

        # data = json.loads(response.json())


        print (data['data'][i]['Title'])




    for i in range(0,3):

        page = str(2)

        url = "https://jsonmock.hackerrank.com/api/movies/search/?Title=%s&page=%s" % (var, page)


# while(int(page)<int(page)+1):

        response = urlopen(url).read().decode('UTF-8')

        data = json.loads(response)

        print (data['data'][i]['Title'])

    # print data2['data'][i]['Title']



getMovieTitles("spiderman")



      #output:

              Italian Spiderman

              Superman, Spiderman or Batman

              Spiderman

              Spiderman

              Fighting, Flying and Driving: The Stunts of Spiderman 3

              Spiderman and Grandma

              The Amazing Spiderman T4 Premiere Special 

              Amazing Spiderman Syndrome

              Hollywood's Master Storytellers: Spiderman Live

              Spiderman 5

              They Call Me Spiderman

              The Death of Spiderman

              Spiderman in Cannes

        #ouput required:

              Amazin Spiderman Syndrome

              Fighting, Flying and Driving: The Stunts of Spiderman 3

              Hollywood's Master Storytellers: Spiderman Live

              ....... and so on NOTICE THE FIRST LETTER IN OUTPUT 

                                    REQUIRED SECTION as its 

                            alphabetically ordered


慕森王
浏览 181回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python