Calling an array element throws error 'list index out of range'










-3















When using 2d arrays, I can add these elements, but it won't let me call an element; it throws a 'list index out of range'



a = 
for i in range (0,10):
x = str(input("insert player x"))
blah.append([x,0])
for i in range(0,10):
bleh = blah[0,1]









share|improve this question



















  • 1





    You defined neither blah nor bleh. This will throw a NameError.

    – DocDriven
    Nov 14 '18 at 9:16












  • blah[0, 1] will throw TypeError: list indices must be integers or slices, not tuple, please give a minimal workable code which can reproduce your issue.

    – lagom
    Nov 14 '18 at 9:17
















-3















When using 2d arrays, I can add these elements, but it won't let me call an element; it throws a 'list index out of range'



a = 
for i in range (0,10):
x = str(input("insert player x"))
blah.append([x,0])
for i in range(0,10):
bleh = blah[0,1]









share|improve this question



















  • 1





    You defined neither blah nor bleh. This will throw a NameError.

    – DocDriven
    Nov 14 '18 at 9:16












  • blah[0, 1] will throw TypeError: list indices must be integers or slices, not tuple, please give a minimal workable code which can reproduce your issue.

    – lagom
    Nov 14 '18 at 9:17














-3












-3








-3








When using 2d arrays, I can add these elements, but it won't let me call an element; it throws a 'list index out of range'



a = 
for i in range (0,10):
x = str(input("insert player x"))
blah.append([x,0])
for i in range(0,10):
bleh = blah[0,1]









share|improve this question
















When using 2d arrays, I can add these elements, but it won't let me call an element; it throws a 'list index out of range'



a = 
for i in range (0,10):
x = str(input("insert player x"))
blah.append([x,0])
for i in range(0,10):
bleh = blah[0,1]






python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 2 '18 at 2:20









Community

11




11










asked Nov 14 '18 at 9:09









person.unknownperson.unknown

12




12







  • 1





    You defined neither blah nor bleh. This will throw a NameError.

    – DocDriven
    Nov 14 '18 at 9:16












  • blah[0, 1] will throw TypeError: list indices must be integers or slices, not tuple, please give a minimal workable code which can reproduce your issue.

    – lagom
    Nov 14 '18 at 9:17













  • 1





    You defined neither blah nor bleh. This will throw a NameError.

    – DocDriven
    Nov 14 '18 at 9:16












  • blah[0, 1] will throw TypeError: list indices must be integers or slices, not tuple, please give a minimal workable code which can reproduce your issue.

    – lagom
    Nov 14 '18 at 9:17








1




1





You defined neither blah nor bleh. This will throw a NameError.

– DocDriven
Nov 14 '18 at 9:16






You defined neither blah nor bleh. This will throw a NameError.

– DocDriven
Nov 14 '18 at 9:16














blah[0, 1] will throw TypeError: list indices must be integers or slices, not tuple, please give a minimal workable code which can reproduce your issue.

– lagom
Nov 14 '18 at 9:17






blah[0, 1] will throw TypeError: list indices must be integers or slices, not tuple, please give a minimal workable code which can reproduce your issue.

– lagom
Nov 14 '18 at 9:17













2 Answers
2






active

oldest

votes


















0














Your question is not clear. In the blah list that you create, why do you need to append 0 with the input? The blah variable is a list of list. For accessing the elements in it, just call the list with i as in blah[i].



Refer to the below code:



blah = 
for i in range (0,10):
x = str(i)
blah.append([x,0])

for i in range(0,10):
bleh = blah[i]





share|improve this answer






























    0














    if i understand you right, this code:



    bleh = 
    blah =
    a =
    for i in range (10):
    x = str(input("insert player x"))
    blah.append([x, i])


    with these inputs:



    insert player x: input1
    insert player x: input2
    insert player x: input3
    insert player x: input4
    insert player x: input5
    insert player x: input6
    insert player x: input7
    insert player x: input8
    insert player x: input9
    insert player x: input10


    gives you this output:



    [[' input1', 0], [' input2', 1], [' input3', 2], [' input4', 3], [' input5', 4], [' input6', 5], [' input7', 6], [' input8', 7], [' input9', 8], [' input10', 9]] 


    I hope that helps.






    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%2f53296494%2fcalling-an-array-element-throws-error-list-index-out-of-range%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









      0














      Your question is not clear. In the blah list that you create, why do you need to append 0 with the input? The blah variable is a list of list. For accessing the elements in it, just call the list with i as in blah[i].



      Refer to the below code:



      blah = 
      for i in range (0,10):
      x = str(i)
      blah.append([x,0])

      for i in range(0,10):
      bleh = blah[i]





      share|improve this answer



























        0














        Your question is not clear. In the blah list that you create, why do you need to append 0 with the input? The blah variable is a list of list. For accessing the elements in it, just call the list with i as in blah[i].



        Refer to the below code:



        blah = 
        for i in range (0,10):
        x = str(i)
        blah.append([x,0])

        for i in range(0,10):
        bleh = blah[i]





        share|improve this answer

























          0












          0








          0







          Your question is not clear. In the blah list that you create, why do you need to append 0 with the input? The blah variable is a list of list. For accessing the elements in it, just call the list with i as in blah[i].



          Refer to the below code:



          blah = 
          for i in range (0,10):
          x = str(i)
          blah.append([x,0])

          for i in range(0,10):
          bleh = blah[i]





          share|improve this answer













          Your question is not clear. In the blah list that you create, why do you need to append 0 with the input? The blah variable is a list of list. For accessing the elements in it, just call the list with i as in blah[i].



          Refer to the below code:



          blah = 
          for i in range (0,10):
          x = str(i)
          blah.append([x,0])

          for i in range(0,10):
          bleh = blah[i]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 9:16









          Pradip GuptaPradip Gupta

          6910




          6910























              0














              if i understand you right, this code:



              bleh = 
              blah =
              a =
              for i in range (10):
              x = str(input("insert player x"))
              blah.append([x, i])


              with these inputs:



              insert player x: input1
              insert player x: input2
              insert player x: input3
              insert player x: input4
              insert player x: input5
              insert player x: input6
              insert player x: input7
              insert player x: input8
              insert player x: input9
              insert player x: input10


              gives you this output:



              [[' input1', 0], [' input2', 1], [' input3', 2], [' input4', 3], [' input5', 4], [' input6', 5], [' input7', 6], [' input8', 7], [' input9', 8], [' input10', 9]] 


              I hope that helps.






              share|improve this answer



























                0














                if i understand you right, this code:



                bleh = 
                blah =
                a =
                for i in range (10):
                x = str(input("insert player x"))
                blah.append([x, i])


                with these inputs:



                insert player x: input1
                insert player x: input2
                insert player x: input3
                insert player x: input4
                insert player x: input5
                insert player x: input6
                insert player x: input7
                insert player x: input8
                insert player x: input9
                insert player x: input10


                gives you this output:



                [[' input1', 0], [' input2', 1], [' input3', 2], [' input4', 3], [' input5', 4], [' input6', 5], [' input7', 6], [' input8', 7], [' input9', 8], [' input10', 9]] 


                I hope that helps.






                share|improve this answer

























                  0












                  0








                  0







                  if i understand you right, this code:



                  bleh = 
                  blah =
                  a =
                  for i in range (10):
                  x = str(input("insert player x"))
                  blah.append([x, i])


                  with these inputs:



                  insert player x: input1
                  insert player x: input2
                  insert player x: input3
                  insert player x: input4
                  insert player x: input5
                  insert player x: input6
                  insert player x: input7
                  insert player x: input8
                  insert player x: input9
                  insert player x: input10


                  gives you this output:



                  [[' input1', 0], [' input2', 1], [' input3', 2], [' input4', 3], [' input5', 4], [' input6', 5], [' input7', 6], [' input8', 7], [' input9', 8], [' input10', 9]] 


                  I hope that helps.






                  share|improve this answer













                  if i understand you right, this code:



                  bleh = 
                  blah =
                  a =
                  for i in range (10):
                  x = str(input("insert player x"))
                  blah.append([x, i])


                  with these inputs:



                  insert player x: input1
                  insert player x: input2
                  insert player x: input3
                  insert player x: input4
                  insert player x: input5
                  insert player x: input6
                  insert player x: input7
                  insert player x: input8
                  insert player x: input9
                  insert player x: input10


                  gives you this output:



                  [[' input1', 0], [' input2', 1], [' input3', 2], [' input4', 3], [' input5', 4], [' input6', 5], [' input7', 6], [' input8', 7], [' input9', 8], [' input10', 9]] 


                  I hope that helps.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 14 '18 at 9:30









                  FlowFlow

                  358




                  358



























                      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%2f53296494%2fcalling-an-array-element-throws-error-list-index-out-of-range%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







                      這個網誌中的熱門文章

                      What does pagestruct do in Eviews?

                      Dutch intervention in Lombok and Karangasem

                      Channel Islands