Python Separate list to be line by line











up vote
0
down vote

favorite












I'm writing a program to do some statistics on some times. I want the output to look like



11: 4
22: 3
33: 1


instead of



11:4, 22:3, 33:1


because I find it hard to read.



Here is the code I have



#Copy solves here, in seconds, seperated by a comma for each solve
times = [11.9, 14.2, 17.3, 11.2 , 123.4]
#Blank list to copy modified solves into
newtimes =
for time in times:
#Rounds down every time
time = int(time)
#Adds time to new list
newtimes.append(time)
#Sorts list lowest to highest
newtimes.sort()
#Gets length of new list, which is amount of solves
solves = len(newtimes)
#Set longest and shortest solve times
longestSolve = max(newtimes)
shortestSolve = min(newtimes)

timesfreq = {i:newtimes.count(i) for i in newtimes}

print(newtimes)
print(timesfreq)
print(solves)
print("Your longest solve was " + str(longestSolve) + " seconds and your shortest solve was " + str(shortestSolve) + " seconds")









share|improve this question


























    up vote
    0
    down vote

    favorite












    I'm writing a program to do some statistics on some times. I want the output to look like



    11: 4
    22: 3
    33: 1


    instead of



    11:4, 22:3, 33:1


    because I find it hard to read.



    Here is the code I have



    #Copy solves here, in seconds, seperated by a comma for each solve
    times = [11.9, 14.2, 17.3, 11.2 , 123.4]
    #Blank list to copy modified solves into
    newtimes =
    for time in times:
    #Rounds down every time
    time = int(time)
    #Adds time to new list
    newtimes.append(time)
    #Sorts list lowest to highest
    newtimes.sort()
    #Gets length of new list, which is amount of solves
    solves = len(newtimes)
    #Set longest and shortest solve times
    longestSolve = max(newtimes)
    shortestSolve = min(newtimes)

    timesfreq = {i:newtimes.count(i) for i in newtimes}

    print(newtimes)
    print(timesfreq)
    print(solves)
    print("Your longest solve was " + str(longestSolve) + " seconds and your shortest solve was " + str(shortestSolve) + " seconds")









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm writing a program to do some statistics on some times. I want the output to look like



      11: 4
      22: 3
      33: 1


      instead of



      11:4, 22:3, 33:1


      because I find it hard to read.



      Here is the code I have



      #Copy solves here, in seconds, seperated by a comma for each solve
      times = [11.9, 14.2, 17.3, 11.2 , 123.4]
      #Blank list to copy modified solves into
      newtimes =
      for time in times:
      #Rounds down every time
      time = int(time)
      #Adds time to new list
      newtimes.append(time)
      #Sorts list lowest to highest
      newtimes.sort()
      #Gets length of new list, which is amount of solves
      solves = len(newtimes)
      #Set longest and shortest solve times
      longestSolve = max(newtimes)
      shortestSolve = min(newtimes)

      timesfreq = {i:newtimes.count(i) for i in newtimes}

      print(newtimes)
      print(timesfreq)
      print(solves)
      print("Your longest solve was " + str(longestSolve) + " seconds and your shortest solve was " + str(shortestSolve) + " seconds")









      share|improve this question













      I'm writing a program to do some statistics on some times. I want the output to look like



      11: 4
      22: 3
      33: 1


      instead of



      11:4, 22:3, 33:1


      because I find it hard to read.



      Here is the code I have



      #Copy solves here, in seconds, seperated by a comma for each solve
      times = [11.9, 14.2, 17.3, 11.2 , 123.4]
      #Blank list to copy modified solves into
      newtimes =
      for time in times:
      #Rounds down every time
      time = int(time)
      #Adds time to new list
      newtimes.append(time)
      #Sorts list lowest to highest
      newtimes.sort()
      #Gets length of new list, which is amount of solves
      solves = len(newtimes)
      #Set longest and shortest solve times
      longestSolve = max(newtimes)
      shortestSolve = min(newtimes)

      timesfreq = {i:newtimes.count(i) for i in newtimes}

      print(newtimes)
      print(timesfreq)
      print(solves)
      print("Your longest solve was " + str(longestSolve) + " seconds and your shortest solve was " + str(shortestSolve) + " seconds")






      python python-3.x list






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 22:25









      Joel Banks

      395




      395
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          just go like this:



          for i in timesfreq.items():
          print(i)


          This gives



          (11, 2)
          (14, 1)
          (17, 1)
          (123, 1)


          If you want it exactly as you stated:



          for a,b in timesfreq.items():
          print("{}: {}".format(a,b))





          share|improve this answer

















          • 1




            Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
            – Joel Banks
            Nov 10 at 22:51


















          up vote
          0
          down vote













          One way you can do this as a one-liner:



          >>> print('n'.join([str(key) + ': ' + str(val) for key, val in timesfreq.items()]))
          123: 1
          17: 1
          11: 2
          14: 1


          Here's a good reference for iterating over key/value pairs in a dictionary: Iterating over dictionaries using 'for' loops






          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',
            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%2f53244030%2fpython-separate-list-to-be-line-by-line%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            just go like this:



            for i in timesfreq.items():
            print(i)


            This gives



            (11, 2)
            (14, 1)
            (17, 1)
            (123, 1)


            If you want it exactly as you stated:



            for a,b in timesfreq.items():
            print("{}: {}".format(a,b))





            share|improve this answer

















            • 1




              Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
              – Joel Banks
              Nov 10 at 22:51















            up vote
            0
            down vote



            accepted










            just go like this:



            for i in timesfreq.items():
            print(i)


            This gives



            (11, 2)
            (14, 1)
            (17, 1)
            (123, 1)


            If you want it exactly as you stated:



            for a,b in timesfreq.items():
            print("{}: {}".format(a,b))





            share|improve this answer

















            • 1




              Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
              – Joel Banks
              Nov 10 at 22:51













            up vote
            0
            down vote



            accepted







            up vote
            0
            down vote



            accepted






            just go like this:



            for i in timesfreq.items():
            print(i)


            This gives



            (11, 2)
            (14, 1)
            (17, 1)
            (123, 1)


            If you want it exactly as you stated:



            for a,b in timesfreq.items():
            print("{}: {}".format(a,b))





            share|improve this answer












            just go like this:



            for i in timesfreq.items():
            print(i)


            This gives



            (11, 2)
            (14, 1)
            (17, 1)
            (123, 1)


            If you want it exactly as you stated:



            for a,b in timesfreq.items():
            print("{}: {}".format(a,b))






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 10 at 22:39









            Christian Sloper

            1,024213




            1,024213








            • 1




              Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
              – Joel Banks
              Nov 10 at 22:51














            • 1




              Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
              – Joel Banks
              Nov 10 at 22:51








            1




            1




            Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
            – Joel Banks
            Nov 10 at 22:51




            Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
            – Joel Banks
            Nov 10 at 22:51












            up vote
            0
            down vote













            One way you can do this as a one-liner:



            >>> print('n'.join([str(key) + ': ' + str(val) for key, val in timesfreq.items()]))
            123: 1
            17: 1
            11: 2
            14: 1


            Here's a good reference for iterating over key/value pairs in a dictionary: Iterating over dictionaries using 'for' loops






            share|improve this answer

























              up vote
              0
              down vote













              One way you can do this as a one-liner:



              >>> print('n'.join([str(key) + ': ' + str(val) for key, val in timesfreq.items()]))
              123: 1
              17: 1
              11: 2
              14: 1


              Here's a good reference for iterating over key/value pairs in a dictionary: Iterating over dictionaries using 'for' loops






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                One way you can do this as a one-liner:



                >>> print('n'.join([str(key) + ': ' + str(val) for key, val in timesfreq.items()]))
                123: 1
                17: 1
                11: 2
                14: 1


                Here's a good reference for iterating over key/value pairs in a dictionary: Iterating over dictionaries using 'for' loops






                share|improve this answer












                One way you can do this as a one-liner:



                >>> print('n'.join([str(key) + ': ' + str(val) for key, val in timesfreq.items()]))
                123: 1
                17: 1
                11: 2
                14: 1


                Here's a good reference for iterating over key/value pairs in a dictionary: Iterating over dictionaries using 'for' loops







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 22:40









                Mixolydian

                613




                613






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244030%2fpython-separate-list-to-be-line-by-line%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

                    Florida Star v. B. J. F.

                    Error while running script in elastic search , gateway timeout

                    Adding quotations to stringified JSON object values