Skip to content

Implement len() for dict_view  #12385

@eleciawhite

Description

@eleciawhite

have a bit of code that works in Python 3.5 but not micropython:

d = {1:"hello", 2:"world"}
len(d)
len(d.items())

In Py3.5 and 2.7, both len(d) and len(d.items()) return 2
In micropython, len(d) is 2 but len(d.items()) throws:

len(d.items())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object of type 'dict_view' has no len()

Note that len(d.items()) == len(d.keys()) == len(d.values()) == len(d) should be true for consistency.

I don't think the version matters but I am running a variant of 1.20.0 on an STM32 L4:

MicroPython 724865b19-dirty on 2023-09-05; NUCLEO-L4A6ZG with STM32L4A6ZG
Type "help()" for more information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature requests, new feature implementations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy