Sort an input by order of importance












-1















I am not a coder but understand python basics. I want my user to input a random list such as:



Reuters
The New York Times
The Wall Street Journal
Associated Press
Financial Times


and for my code to sort it based on the index postion:



outlet = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']


so it prints ordered and on a new line:



The Wall Street Journal 
The New York Times
Associated Press
Reuters
Financial Times


Thank you!



The code I have so far is as follows:



 ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
print('Enter new coverage:')
coverage = input()
listed = coverage.split()
print(*listed, sep="n")









share|improve this question

























  • Which part you do not understand: how to let the user enter the list or how to sort it once it is entered? As written, your question is too broad.

    – DYZ
    Jan 3 at 6:56













  • Thanks for your response, I want to know how to sort the entered list based on the rank, here is what I have: code ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] print('Enter new coverage:') coverage = input() listed = coverage.split() print(*listed, sep="n")

    – Sandy Karp
    Jan 3 at 7:12













  • Please do not post code in comments. Edit your original question.

    – DYZ
    Jan 3 at 7:14
















-1















I am not a coder but understand python basics. I want my user to input a random list such as:



Reuters
The New York Times
The Wall Street Journal
Associated Press
Financial Times


and for my code to sort it based on the index postion:



outlet = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']


so it prints ordered and on a new line:



The Wall Street Journal 
The New York Times
Associated Press
Reuters
Financial Times


Thank you!



The code I have so far is as follows:



 ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
print('Enter new coverage:')
coverage = input()
listed = coverage.split()
print(*listed, sep="n")









share|improve this question

























  • Which part you do not understand: how to let the user enter the list or how to sort it once it is entered? As written, your question is too broad.

    – DYZ
    Jan 3 at 6:56













  • Thanks for your response, I want to know how to sort the entered list based on the rank, here is what I have: code ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] print('Enter new coverage:') coverage = input() listed = coverage.split() print(*listed, sep="n")

    – Sandy Karp
    Jan 3 at 7:12













  • Please do not post code in comments. Edit your original question.

    – DYZ
    Jan 3 at 7:14














-1












-1








-1








I am not a coder but understand python basics. I want my user to input a random list such as:



Reuters
The New York Times
The Wall Street Journal
Associated Press
Financial Times


and for my code to sort it based on the index postion:



outlet = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']


so it prints ordered and on a new line:



The Wall Street Journal 
The New York Times
Associated Press
Reuters
Financial Times


Thank you!



The code I have so far is as follows:



 ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
print('Enter new coverage:')
coverage = input()
listed = coverage.split()
print(*listed, sep="n")









share|improve this question
















I am not a coder but understand python basics. I want my user to input a random list such as:



Reuters
The New York Times
The Wall Street Journal
Associated Press
Financial Times


and for my code to sort it based on the index postion:



outlet = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']


so it prints ordered and on a new line:



The Wall Street Journal 
The New York Times
Associated Press
Reuters
Financial Times


Thank you!



The code I have so far is as follows:



 ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
print('Enter new coverage:')
coverage = input()
listed = coverage.split()
print(*listed, sep="n")






python list sorting indexing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 11 at 16:36









Machavity

24.7k135981




24.7k135981










asked Jan 3 at 6:51









Sandy KarpSandy Karp

11




11













  • Which part you do not understand: how to let the user enter the list or how to sort it once it is entered? As written, your question is too broad.

    – DYZ
    Jan 3 at 6:56













  • Thanks for your response, I want to know how to sort the entered list based on the rank, here is what I have: code ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] print('Enter new coverage:') coverage = input() listed = coverage.split() print(*listed, sep="n")

    – Sandy Karp
    Jan 3 at 7:12













  • Please do not post code in comments. Edit your original question.

    – DYZ
    Jan 3 at 7:14



















  • Which part you do not understand: how to let the user enter the list or how to sort it once it is entered? As written, your question is too broad.

    – DYZ
    Jan 3 at 6:56













  • Thanks for your response, I want to know how to sort the entered list based on the rank, here is what I have: code ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] print('Enter new coverage:') coverage = input() listed = coverage.split() print(*listed, sep="n")

    – Sandy Karp
    Jan 3 at 7:12













  • Please do not post code in comments. Edit your original question.

    – DYZ
    Jan 3 at 7:14

















Which part you do not understand: how to let the user enter the list or how to sort it once it is entered? As written, your question is too broad.

– DYZ
Jan 3 at 6:56







Which part you do not understand: how to let the user enter the list or how to sort it once it is entered? As written, your question is too broad.

– DYZ
Jan 3 at 6:56















Thanks for your response, I want to know how to sort the entered list based on the rank, here is what I have: code ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] print('Enter new coverage:') coverage = input() listed = coverage.split() print(*listed, sep="n")

– Sandy Karp
Jan 3 at 7:12







Thanks for your response, I want to know how to sort the entered list based on the rank, here is what I have: code ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] print('Enter new coverage:') coverage = input() listed = coverage.split() print(*listed, sep="n")

– Sandy Karp
Jan 3 at 7:12















Please do not post code in comments. Edit your original question.

– DYZ
Jan 3 at 7:14





Please do not post code in comments. Edit your original question.

– DYZ
Jan 3 at 7:14












1 Answer
1






active

oldest

votes


















0














Ok, so if you have the list a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times] and you want to to sort it with respect to list ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] you can do it by iterating through the ranking list and see if the list a has the first element of the ranking list, if it has the second and so on. The code would be something like this:



a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']

for element in ranking:
for i in a:
if i == element:
print(i)


Result:



The Wall Street Journal
The New York Times
Associated Press
Reuters
Financial Times





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017575%2fsort-an-input-by-order-of-importance%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Ok, so if you have the list a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times] and you want to to sort it with respect to list ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] you can do it by iterating through the ranking list and see if the list a has the first element of the ranking list, if it has the second and so on. The code would be something like this:



    a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
    ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']

    for element in ranking:
    for i in a:
    if i == element:
    print(i)


    Result:



    The Wall Street Journal
    The New York Times
    Associated Press
    Reuters
    Financial Times





    share|improve this answer




























      0














      Ok, so if you have the list a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times] and you want to to sort it with respect to list ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] you can do it by iterating through the ranking list and see if the list a has the first element of the ranking list, if it has the second and so on. The code would be something like this:



      a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
      ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']

      for element in ranking:
      for i in a:
      if i == element:
      print(i)


      Result:



      The Wall Street Journal
      The New York Times
      Associated Press
      Reuters
      Financial Times





      share|improve this answer


























        0












        0








        0







        Ok, so if you have the list a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times] and you want to to sort it with respect to list ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] you can do it by iterating through the ranking list and see if the list a has the first element of the ranking list, if it has the second and so on. The code would be something like this:



        a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
        ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']

        for element in ranking:
        for i in a:
        if i == element:
        print(i)


        Result:



        The Wall Street Journal
        The New York Times
        Associated Press
        Reuters
        Financial Times





        share|improve this answer













        Ok, so if you have the list a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times] and you want to to sort it with respect to list ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] you can do it by iterating through the ranking list and see if the list a has the first element of the ranking list, if it has the second and so on. The code would be something like this:



        a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
        ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']

        for element in ranking:
        for i in a:
        if i == element:
        print(i)


        Result:



        The Wall Street Journal
        The New York Times
        Associated Press
        Reuters
        Financial Times






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 8:55









        NovakNovak

        1,4941615




        1,4941615
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017575%2fsort-an-input-by-order-of-importance%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas