Python Forum
TypeError: 'dict_items' object does not support indexingw
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: 'dict_items' object does not support indexingw
#1
why does 'dict_items' not support indexing? this is the object type you get from dict.items(). shouldn't it interface like a tuple?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Presumably because the order of items isn't meaningful, in the same way it isn't meaningful for a dict.
Reply
#3
check https://stackoverflow.com/a/52900459/4046632
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
(May-04-2022, 05:10 PM)ndc85430 Wrote: Presumably because the order of items isn't meaningful, in the same way it isn't meaningful for a dict.
because of the lack of indexing, it can't behave like a tuple and be used by code that intentionally accesses it with indexing for one of a few reasons i have come across even though in the case of dict.items, none of those reasons were involved. i ended up coding an almost duplicate function just to handle it as an iterator. what was being done need to do reverse-order access some segments of the tuples it got, and it needed to handle it with indexing to keep the access in sync.

the order of items in dict.items values truly had no meaning. but the code needed to handle it that way to avoid the duplication so that other cases that needed to, could use indexing.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020