简体   繁体   English

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

[英]how to print sorted multiple sentences alphabetically in python?

I am having trouble getting the output. 我在获取输出时遇到问题。 I am getting unordered sentences as output and I need them alphabetically sorted. 我收到的句子无序输出,需要按字母顺序对它们进行排序。

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

将标题保存到列表mylist ,然后调用mylist.sort()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何按字母顺序在Python中连接多个排序文件? - how to join multiple sorted files in Python alphabetically? 如何在 Python 中按键创建排序字典(按字母顺序) - How to create a sorted dictionary in Python by key (alphabetically) 如何从 Python 句子列表中打印单个句子? - How do I print individual sentences from a Python list of sentences? 如何在 python 中按字母顺序打印两列 - How to print two columns alphabetically in python Python:我应该在连续句子中使用多个打印语句还是“ +”? - Python: Should I use multiple print statements or “+” for consecutive sentences? 如何在python中将多个句子转换成bigram - how to convert multiple sentences into bigram in python 如何在python中使用递归打印字符串的排序排列 - how to print sorted permutation of a string with recursion in python 如何在python中打印两个句子中相同的单词? - How do I print words that are the same in two sentences in python? 如何在 Python 中的图像上打印印地语句子 (unicode)? - How can I print Hindi sentences(unicode) on image in Python? 如何在 Python 中按字母升序对列表中的多个字符串进行排序 - How to sort multiple strings inside list alphabetically ascending in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM