Convert List of string to Integer












-2















I have a list whose elements are only single string.



my_list = ['9', '4', '4', '5', '4', '3', '5']


How can I convert this into a single integer like: 9445435



Note: ' '.join() only works for lists of strings, not integers.










share|improve this question




















  • 3





    Use join and then cast it to int! like => int(''.join(my_list))

    – DarkSuniuM
    Nov 20 '18 at 8:43






  • 1





    Is your list made of integers or of strings? If integers, then int(''.join(str(v) for v in my_list)), otherwise what DarkSuniuM said

    – FernAndr
    Nov 20 '18 at 8:45








  • 1





    You say it's a list of integers, but the list you have in your question contains strings, not integers.

    – khelwood
    Nov 20 '18 at 8:53


















-2















I have a list whose elements are only single string.



my_list = ['9', '4', '4', '5', '4', '3', '5']


How can I convert this into a single integer like: 9445435



Note: ' '.join() only works for lists of strings, not integers.










share|improve this question




















  • 3





    Use join and then cast it to int! like => int(''.join(my_list))

    – DarkSuniuM
    Nov 20 '18 at 8:43






  • 1





    Is your list made of integers or of strings? If integers, then int(''.join(str(v) for v in my_list)), otherwise what DarkSuniuM said

    – FernAndr
    Nov 20 '18 at 8:45








  • 1





    You say it's a list of integers, but the list you have in your question contains strings, not integers.

    – khelwood
    Nov 20 '18 at 8:53
















-2












-2








-2








I have a list whose elements are only single string.



my_list = ['9', '4', '4', '5', '4', '3', '5']


How can I convert this into a single integer like: 9445435



Note: ' '.join() only works for lists of strings, not integers.










share|improve this question
















I have a list whose elements are only single string.



my_list = ['9', '4', '4', '5', '4', '3', '5']


How can I convert this into a single integer like: 9445435



Note: ' '.join() only works for lists of strings, not integers.







python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 9:02









eyllanesc

79.4k103258




79.4k103258










asked Nov 20 '18 at 8:42









Oliver MurfettOliver Murfett

175




175








  • 3





    Use join and then cast it to int! like => int(''.join(my_list))

    – DarkSuniuM
    Nov 20 '18 at 8:43






  • 1





    Is your list made of integers or of strings? If integers, then int(''.join(str(v) for v in my_list)), otherwise what DarkSuniuM said

    – FernAndr
    Nov 20 '18 at 8:45








  • 1





    You say it's a list of integers, but the list you have in your question contains strings, not integers.

    – khelwood
    Nov 20 '18 at 8:53
















  • 3





    Use join and then cast it to int! like => int(''.join(my_list))

    – DarkSuniuM
    Nov 20 '18 at 8:43






  • 1





    Is your list made of integers or of strings? If integers, then int(''.join(str(v) for v in my_list)), otherwise what DarkSuniuM said

    – FernAndr
    Nov 20 '18 at 8:45








  • 1





    You say it's a list of integers, but the list you have in your question contains strings, not integers.

    – khelwood
    Nov 20 '18 at 8:53










3




3





Use join and then cast it to int! like => int(''.join(my_list))

– DarkSuniuM
Nov 20 '18 at 8:43





Use join and then cast it to int! like => int(''.join(my_list))

– DarkSuniuM
Nov 20 '18 at 8:43




1




1





Is your list made of integers or of strings? If integers, then int(''.join(str(v) for v in my_list)), otherwise what DarkSuniuM said

– FernAndr
Nov 20 '18 at 8:45







Is your list made of integers or of strings? If integers, then int(''.join(str(v) for v in my_list)), otherwise what DarkSuniuM said

– FernAndr
Nov 20 '18 at 8:45






1




1





You say it's a list of integers, but the list you have in your question contains strings, not integers.

– khelwood
Nov 20 '18 at 8:53







You say it's a list of integers, but the list you have in your question contains strings, not integers.

– khelwood
Nov 20 '18 at 8:53














3 Answers
3






active

oldest

votes


















0














Try this,



In [5]: int(''.join(my_list))
Out[5]: 9445435





share|improve this answer































    0














    Why don't you try this approach?



    my_list = ['9', '4', '4', '5', '4', '3', '5']
    output = int(''.join(str(num) for num in my_list))
    print(output) ## 9445435





    share|improve this answer



















    • 1





      or output = int(''.join(my_list))

      – eyllanesc
      Nov 20 '18 at 8:51











    • @eyllanesc nah, the for is there so if the list items was int, it casts them to str

      – DarkSuniuM
      Nov 20 '18 at 8:53






    • 1





      @DarkSuniuM join accepts an iterable and converts them internally with str() to each iterable element, the for is unnecessary

      – eyllanesc
      Nov 20 '18 at 8:55













    • @eyllanesc TypeError: sequence item 0: expected str instance, int found

      – DarkSuniuM
      Nov 20 '18 at 8:56











    • @DarkSuniuM my_list = ['9', '4', '4', '5', '4', '3', '5'] output = int(''.join(my_list)) print(output) ---> 9445435 in Python 2.7.15 and python 3.7.1

      – eyllanesc
      Nov 20 '18 at 8:58



















    0














    result = ' '.join(my_list)

    result = int(result)





    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%2f53389136%2fconvert-list-of-string-to-integer%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Try this,



      In [5]: int(''.join(my_list))
      Out[5]: 9445435





      share|improve this answer




























        0














        Try this,



        In [5]: int(''.join(my_list))
        Out[5]: 9445435





        share|improve this answer


























          0












          0








          0







          Try this,



          In [5]: int(''.join(my_list))
          Out[5]: 9445435





          share|improve this answer













          Try this,



          In [5]: int(''.join(my_list))
          Out[5]: 9445435






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 8:49









          Rahul K PRahul K P

          7,37122234




          7,37122234

























              0














              Why don't you try this approach?



              my_list = ['9', '4', '4', '5', '4', '3', '5']
              output = int(''.join(str(num) for num in my_list))
              print(output) ## 9445435





              share|improve this answer



















              • 1





                or output = int(''.join(my_list))

                – eyllanesc
                Nov 20 '18 at 8:51











              • @eyllanesc nah, the for is there so if the list items was int, it casts them to str

                – DarkSuniuM
                Nov 20 '18 at 8:53






              • 1





                @DarkSuniuM join accepts an iterable and converts them internally with str() to each iterable element, the for is unnecessary

                – eyllanesc
                Nov 20 '18 at 8:55













              • @eyllanesc TypeError: sequence item 0: expected str instance, int found

                – DarkSuniuM
                Nov 20 '18 at 8:56











              • @DarkSuniuM my_list = ['9', '4', '4', '5', '4', '3', '5'] output = int(''.join(my_list)) print(output) ---> 9445435 in Python 2.7.15 and python 3.7.1

                – eyllanesc
                Nov 20 '18 at 8:58
















              0














              Why don't you try this approach?



              my_list = ['9', '4', '4', '5', '4', '3', '5']
              output = int(''.join(str(num) for num in my_list))
              print(output) ## 9445435





              share|improve this answer



















              • 1





                or output = int(''.join(my_list))

                – eyllanesc
                Nov 20 '18 at 8:51











              • @eyllanesc nah, the for is there so if the list items was int, it casts them to str

                – DarkSuniuM
                Nov 20 '18 at 8:53






              • 1





                @DarkSuniuM join accepts an iterable and converts them internally with str() to each iterable element, the for is unnecessary

                – eyllanesc
                Nov 20 '18 at 8:55













              • @eyllanesc TypeError: sequence item 0: expected str instance, int found

                – DarkSuniuM
                Nov 20 '18 at 8:56











              • @DarkSuniuM my_list = ['9', '4', '4', '5', '4', '3', '5'] output = int(''.join(my_list)) print(output) ---> 9445435 in Python 2.7.15 and python 3.7.1

                – eyllanesc
                Nov 20 '18 at 8:58














              0












              0








              0







              Why don't you try this approach?



              my_list = ['9', '4', '4', '5', '4', '3', '5']
              output = int(''.join(str(num) for num in my_list))
              print(output) ## 9445435





              share|improve this answer













              Why don't you try this approach?



              my_list = ['9', '4', '4', '5', '4', '3', '5']
              output = int(''.join(str(num) for num in my_list))
              print(output) ## 9445435






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 20 '18 at 8:50









              toom501toom501

              3021313




              3021313








              • 1





                or output = int(''.join(my_list))

                – eyllanesc
                Nov 20 '18 at 8:51











              • @eyllanesc nah, the for is there so if the list items was int, it casts them to str

                – DarkSuniuM
                Nov 20 '18 at 8:53






              • 1





                @DarkSuniuM join accepts an iterable and converts them internally with str() to each iterable element, the for is unnecessary

                – eyllanesc
                Nov 20 '18 at 8:55













              • @eyllanesc TypeError: sequence item 0: expected str instance, int found

                – DarkSuniuM
                Nov 20 '18 at 8:56











              • @DarkSuniuM my_list = ['9', '4', '4', '5', '4', '3', '5'] output = int(''.join(my_list)) print(output) ---> 9445435 in Python 2.7.15 and python 3.7.1

                – eyllanesc
                Nov 20 '18 at 8:58














              • 1





                or output = int(''.join(my_list))

                – eyllanesc
                Nov 20 '18 at 8:51











              • @eyllanesc nah, the for is there so if the list items was int, it casts them to str

                – DarkSuniuM
                Nov 20 '18 at 8:53






              • 1





                @DarkSuniuM join accepts an iterable and converts them internally with str() to each iterable element, the for is unnecessary

                – eyllanesc
                Nov 20 '18 at 8:55













              • @eyllanesc TypeError: sequence item 0: expected str instance, int found

                – DarkSuniuM
                Nov 20 '18 at 8:56











              • @DarkSuniuM my_list = ['9', '4', '4', '5', '4', '3', '5'] output = int(''.join(my_list)) print(output) ---> 9445435 in Python 2.7.15 and python 3.7.1

                – eyllanesc
                Nov 20 '18 at 8:58








              1




              1





              or output = int(''.join(my_list))

              – eyllanesc
              Nov 20 '18 at 8:51





              or output = int(''.join(my_list))

              – eyllanesc
              Nov 20 '18 at 8:51













              @eyllanesc nah, the for is there so if the list items was int, it casts them to str

              – DarkSuniuM
              Nov 20 '18 at 8:53





              @eyllanesc nah, the for is there so if the list items was int, it casts them to str

              – DarkSuniuM
              Nov 20 '18 at 8:53




              1




              1





              @DarkSuniuM join accepts an iterable and converts them internally with str() to each iterable element, the for is unnecessary

              – eyllanesc
              Nov 20 '18 at 8:55







              @DarkSuniuM join accepts an iterable and converts them internally with str() to each iterable element, the for is unnecessary

              – eyllanesc
              Nov 20 '18 at 8:55















              @eyllanesc TypeError: sequence item 0: expected str instance, int found

              – DarkSuniuM
              Nov 20 '18 at 8:56





              @eyllanesc TypeError: sequence item 0: expected str instance, int found

              – DarkSuniuM
              Nov 20 '18 at 8:56













              @DarkSuniuM my_list = ['9', '4', '4', '5', '4', '3', '5'] output = int(''.join(my_list)) print(output) ---> 9445435 in Python 2.7.15 and python 3.7.1

              – eyllanesc
              Nov 20 '18 at 8:58





              @DarkSuniuM my_list = ['9', '4', '4', '5', '4', '3', '5'] output = int(''.join(my_list)) print(output) ---> 9445435 in Python 2.7.15 and python 3.7.1

              – eyllanesc
              Nov 20 '18 at 8:58











              0














              result = ' '.join(my_list)

              result = int(result)





              share|improve this answer






























                0














                result = ' '.join(my_list)

                result = int(result)





                share|improve this answer




























                  0












                  0








                  0







                  result = ' '.join(my_list)

                  result = int(result)





                  share|improve this answer















                  result = ' '.join(my_list)

                  result = int(result)






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 20 '18 at 8:52









                  AkshayNevrekar

                  4,83791837




                  4,83791837










                  answered Nov 20 '18 at 8:48









                  crazy_codercrazy_coder

                  14116




                  14116






























                      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%2f53389136%2fconvert-list-of-string-to-integer%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







                      這個網誌中的熱門文章

                      Hercules Kyvelos

                      Tangent Lines Diagram Along Smooth Curve

                      Yusuf al-Mu'taman ibn Hud