Different ValueError for the same operation in List and TupleHow do I check if a list is empty?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?Does Python have a ternary conditional operator?What's the difference between lists and tuples?How to make a flat list out of list of listsHow do I concatenate two lists in Python?How to clone or copy a list?How do I list all files of a directory?
How to avoid unconsciously copying the style of my favorite writer?
Is there anything wrong with Thrawn?
3D Statue Park: U shapes
How much were the LMs maneuvered to their landing points?
Word for showing a small part of something briefly to hint to its existence or beauty without fully uncovering it
Did the IBM PC use the 8088's NMI line?
Is dd if=/dev/urandom of=/dev/mem safe?
Problem in styling a monochrome plot
Is it normal practice to screen share with a client?
AC contactor 1 pole or 2?
Keeping an "hot eyeball planet" wet
Why did Saturn V not head straight to the moon?
Why are so many countries still in the Commonwealth?
Examples of simultaneous independent breakthroughs
Why can't my huge trees be chopped down?
When going by a train from Paris to Düsseldorf (Thalys), can I hop off in Köln and then hop on again?
Trapped in an ocean Temple in Minecraft?
Writing a clean implementation of Rock, Paper, Scissors game in c++
401(k) investment after being fired. Do I own it?
Why/when is AC-DC-AC conversion superior to direct AC-Ac conversion?
Anybody know what this small Nintendo stand is for?
What's the difference between 2a and 10a charging options?
Is it legal for private citizens to "impound" e-scooters?
Weed in Massachusetts: underground roots, skunky smell when bruised
Different ValueError for the same operation in List and Tuple
How do I check if a list is empty?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?Does Python have a ternary conditional operator?What's the difference between lists and tuples?How to make a flat list out of list of listsHow do I concatenate two lists in Python?How to clone or copy a list?How do I list all files of a directory?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am curious why ValueErrors are different in List and Tuple when I try to get an index. ValueError of a list returns in well format with actual argument "ValueError: 'ITEM' is not in list", whereas tuple returns something like this "ValueError: tuple.index(x): x not in tuple".
I think List and Tuple both are calling same index() method then why it is raising different ValueErrors?
>>> jframe_li
['Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js']
>>> jframe_tu
('Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js')
>>> jframe_li.index('React')
1
>>> jframe_tu.index('React')
1
>>> jframe_li.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: 'react' is not in list
>>> jframe_tu.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: tuple.index(x): x not in tuple
python python-3.x list tuples
add a comment |
I am curious why ValueErrors are different in List and Tuple when I try to get an index. ValueError of a list returns in well format with actual argument "ValueError: 'ITEM' is not in list", whereas tuple returns something like this "ValueError: tuple.index(x): x not in tuple".
I think List and Tuple both are calling same index() method then why it is raising different ValueErrors?
>>> jframe_li
['Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js']
>>> jframe_tu
('Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js')
>>> jframe_li.index('React')
1
>>> jframe_tu.index('React')
1
>>> jframe_li.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: 'react' is not in list
>>> jframe_tu.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: tuple.index(x): x not in tuple
python python-3.x list tuples
"I think List and Tuple both are calling same index() method" - I'm not sure this is a valid assumption.
– snakecharmerb
Mar 26 at 17:34
@snakecharmerb According to docs, Tuples implement all of the common sequence operations which include.index
, now would you say it implements it in a different way?
– Samuel
Mar 26 at 17:43
@Samuel as the answer below demonstrates, I would say that they are implemented differently.
– snakecharmerb
Mar 26 at 19:59
Yeah, you were right, I also learned in the process.
– Samuel
Mar 26 at 20:00
add a comment |
I am curious why ValueErrors are different in List and Tuple when I try to get an index. ValueError of a list returns in well format with actual argument "ValueError: 'ITEM' is not in list", whereas tuple returns something like this "ValueError: tuple.index(x): x not in tuple".
I think List and Tuple both are calling same index() method then why it is raising different ValueErrors?
>>> jframe_li
['Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js']
>>> jframe_tu
('Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js')
>>> jframe_li.index('React')
1
>>> jframe_tu.index('React')
1
>>> jframe_li.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: 'react' is not in list
>>> jframe_tu.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: tuple.index(x): x not in tuple
python python-3.x list tuples
I am curious why ValueErrors are different in List and Tuple when I try to get an index. ValueError of a list returns in well format with actual argument "ValueError: 'ITEM' is not in list", whereas tuple returns something like this "ValueError: tuple.index(x): x not in tuple".
I think List and Tuple both are calling same index() method then why it is raising different ValueErrors?
>>> jframe_li
['Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js']
>>> jframe_tu
('Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js')
>>> jframe_li.index('React')
1
>>> jframe_tu.index('React')
1
>>> jframe_li.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: 'react' is not in list
>>> jframe_tu.index('react')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: tuple.index(x): x not in tuple
python python-3.x list tuples
python python-3.x list tuples
edited Mar 26 at 17:18
Aran-Fey
20.3k5 gold badges43 silver badges82 bronze badges
20.3k5 gold badges43 silver badges82 bronze badges
asked Mar 26 at 17:18
Hardik PatelHardik Patel
336 bronze badges
336 bronze badges
"I think List and Tuple both are calling same index() method" - I'm not sure this is a valid assumption.
– snakecharmerb
Mar 26 at 17:34
@snakecharmerb According to docs, Tuples implement all of the common sequence operations which include.index
, now would you say it implements it in a different way?
– Samuel
Mar 26 at 17:43
@Samuel as the answer below demonstrates, I would say that they are implemented differently.
– snakecharmerb
Mar 26 at 19:59
Yeah, you were right, I also learned in the process.
– Samuel
Mar 26 at 20:00
add a comment |
"I think List and Tuple both are calling same index() method" - I'm not sure this is a valid assumption.
– snakecharmerb
Mar 26 at 17:34
@snakecharmerb According to docs, Tuples implement all of the common sequence operations which include.index
, now would you say it implements it in a different way?
– Samuel
Mar 26 at 17:43
@Samuel as the answer below demonstrates, I would say that they are implemented differently.
– snakecharmerb
Mar 26 at 19:59
Yeah, you were right, I also learned in the process.
– Samuel
Mar 26 at 20:00
"I think List and Tuple both are calling same index() method" - I'm not sure this is a valid assumption.
– snakecharmerb
Mar 26 at 17:34
"I think List and Tuple both are calling same index() method" - I'm not sure this is a valid assumption.
– snakecharmerb
Mar 26 at 17:34
@snakecharmerb According to docs, Tuples implement all of the common sequence operations which include
.index
, now would you say it implements it in a different way?– Samuel
Mar 26 at 17:43
@snakecharmerb According to docs, Tuples implement all of the common sequence operations which include
.index
, now would you say it implements it in a different way?– Samuel
Mar 26 at 17:43
@Samuel as the answer below demonstrates, I would say that they are implemented differently.
– snakecharmerb
Mar 26 at 19:59
@Samuel as the answer below demonstrates, I would say that they are implemented differently.
– snakecharmerb
Mar 26 at 19:59
Yeah, you were right, I also learned in the process.
– Samuel
Mar 26 at 20:00
Yeah, you were right, I also learned in the process.
– Samuel
Mar 26 at 20:00
add a comment |
1 Answer
1
active
oldest
votes
There are implementation differences in the index
methods for lists and tuples, including in the text of a raised ValueError
.
See ValueError string for tuple.index and ValueError string for list.index
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%2f55362835%2fdifferent-valueerror-for-the-same-operation-in-list-and-tuple%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
There are implementation differences in the index
methods for lists and tuples, including in the text of a raised ValueError
.
See ValueError string for tuple.index and ValueError string for list.index
add a comment |
There are implementation differences in the index
methods for lists and tuples, including in the text of a raised ValueError
.
See ValueError string for tuple.index and ValueError string for list.index
add a comment |
There are implementation differences in the index
methods for lists and tuples, including in the text of a raised ValueError
.
See ValueError string for tuple.index and ValueError string for list.index
There are implementation differences in the index
methods for lists and tuples, including in the text of a raised ValueError
.
See ValueError string for tuple.index and ValueError string for list.index
answered Mar 26 at 18:50
benvcbenvc
8,3041 gold badge13 silver badges30 bronze badges
8,3041 gold badge13 silver badges30 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55362835%2fdifferent-valueerror-for-the-same-operation-in-list-and-tuple%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
"I think List and Tuple both are calling same index() method" - I'm not sure this is a valid assumption.
– snakecharmerb
Mar 26 at 17:34
@snakecharmerb According to docs, Tuples implement all of the common sequence operations which include
.index
, now would you say it implements it in a different way?– Samuel
Mar 26 at 17:43
@Samuel as the answer below demonstrates, I would say that they are implemented differently.
– snakecharmerb
Mar 26 at 19:59
Yeah, you were right, I also learned in the process.
– Samuel
Mar 26 at 20:00