Skip to content

What is the guidance around list()? #1300

Answered by soraros
cjohnson318 asked this question in Q&A
Discussion options

You must be logged in to vote

Mojo currently lacks a data type equivalent to Python's list, which is likely due to ongoing work on traits. An alternative, such as DynamicVector, exists, but it is not yet integrated with the ListLiteral mechanism. Therefore, relying on constructors (akin to Python's list()) remains necessary.

That said, I think list() is an anti-pattern in Python. Because list is really a dynamic variable that usually binds to the buildins.list, Python will generate an extra LOAD_GLOBAL so the resultant byte code is slightly worse. I don't think it will greatly affect the actual performance of your Python code, it's just a good to know. dict has some slight overhead for the same reason.

from dis import d…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@cjohnson318
Comment options

Answer selected by cjohnson318
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants