Calling an array element throws error 'list index out of range'
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
add a comment |
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
1
You defined neitherblahnorbleh. This will throw a NameError.
– DocDriven
Nov 14 '18 at 9:16
blah[0, 1]will throwTypeError: 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
add a comment |
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
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
python-3.x
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 neitherblahnorbleh. This will throw a NameError.
– DocDriven
Nov 14 '18 at 9:16
blah[0, 1]will throwTypeError: 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
add a comment |
1
You defined neitherblahnorbleh. This will throw a NameError.
– DocDriven
Nov 14 '18 at 9:16
blah[0, 1]will throwTypeError: 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
add a comment |
2 Answers
2
active
oldest
votes
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]
add a comment |
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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]
add a comment |
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]
add a comment |
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]
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]
answered Nov 14 '18 at 9:16
Pradip GuptaPradip Gupta
6910
6910
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 14 '18 at 9:30
FlowFlow
358
358
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
You defined neither
blahnorbleh. This will throw a NameError.– DocDriven
Nov 14 '18 at 9:16
blah[0, 1]will throwTypeError: 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