Skip to main content

All Questions

0 votes
1 answer
106 views

Is Python's map function evaluation lazy?

I've been solving LeetCode's 1331. Rank Transform of an Array challenge and came up with this one-line solution: class Solution: def arrayRankTransform(self): return map({e: i for i, e in ...
diduk001's user avatar
  • 218
0 votes
0 answers
143 views

POLARS: pycharm exited with following error code : -1073741819 (0xC0000005) while converting lazyframes to polars dataframe using lf.collect()

I have a piece of code which is performing some computations on top of lazy frames. I have the output stored in form of lazy frames in a dictionary. At the end, I am converting the outputs to pandas ...
Surender Reddy Chitteddy's user avatar
2 votes
1 answer
493 views

Eager map in Python

In Python the map function is lazy, but most often I need an eager map. For example, trying to slice a map object results in an error: >>>> map(abs, [3, -1, -4, 1])[1:] Traceback (most ...
user2373145's user avatar
1 vote
1 answer
231 views

Is there "non-lazy mode" or "strict mode" for "querysets" in Django?

When I use select_for_update() and update() of a queryset together as shown below: # "store/views.py" from django.db import transaction from .models import Person from django.http import ...
Super Kai - Kazuya Ito's user avatar
0 votes
1 answer
859 views

Python Hypothesis testing: Is there a way to avoid drawing a LazyStrategy?

If Python hypothesis strategies are too deeply nested, using draw will not create an actual example, but a LazyStrategy. This can be quite problematic at times because the resulting object behaves ...
SmCaterpillar's user avatar
0 votes
2 answers
243 views

lazy evaluation python data structure

I have the following code: def get_data(): return {"a": 1, "b":2} def main(): lazy_dic = lambda : get_data() a_value = lazy_dic()["a"] b_value = lazy_dic()...
Dan The Man's user avatar
  • 1,895
4 votes
2 answers
2k views

Lazy evaluation of dict values?

Suppose I have the following dict d={'a': heavy_expression1, 'b': heavy_expression2}. How can I wrap the expressions, so that they are evaluated once they are accessed and after this no evaluation is ...
Paul R's user avatar
  • 2,817
0 votes
0 answers
308 views

How to create lazy variable that is not a a property/attribute? [duplicate]

At this point, I have found several python implementations for lazily-evaluated property/attribute (also known as cached method), these include: https://boltons.readthedocs.io/en/latest/index.html ...
tribbloid's user avatar
  • 3,898
7 votes
1 answer
651 views

Apply python lazy map for in-place functions?

Sometimes, I build up a thing by repeatedly applying map, and then having python perform the operations all at once. For example, I could build up a list of lists of ranges like so: foo = [256]*3 ...
Him's user avatar
  • 5,547
4 votes
1 answer
4k views

Lazy evaluation when use lambda and list comprehension [duplicate]

Here is the example python code. f_list = [lambda x : x ** i for i in range(5)] [f_list[j](10) for j in range(5)] I thought the output would be: [1, 10, 100, 1000, 10000] But I got this instead: [...
user avatar
1 vote
2 answers
2k views

method chain lazy execution in python [closed]

I have a chain of methods in my python program of the TestClass object like below:- TestClass().method1(args).method2(args).method3(args) I want to build a utility which will scan the above chain and ...
dks551's user avatar
  • 1,123
2 votes
0 answers
472 views

Python: How to access instance attributes in nested descriptors?

Example Take the following example class Leaf: def __get__(self, instance, owner): if instance is None: return self # TODO How to access Root.value here? class ...
Manuel L's user avatar
0 votes
1 answer
583 views

Python3, a lazy print

for my last project in Python3, i used a custom lazy generator to generate my data. Then use imap from a Pool (multiprocessing). So at this point, not any computation have been made. The next step is ...
Paul's user avatar
  • 333
16 votes
4 answers
15k views

How to add a classmethod in Python dynamically

I'm using Python 3. I know about the @classmethod decorator. Also, I know that classmethods can be called from instances. class HappyClass(object): @classmethod def say_hello(): print(...
jleeothon's user avatar
  • 3,186
0 votes
2 answers
4k views

Does range involve eager or lazy evaluation, in 2.x and 3.x? [duplicate]

I was looking at the range function and an online search shows that (EDIT: in 2.x) it's eagerly evaluated >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] However when I try the code below in my ...
Nikos Athanasiou's user avatar

15 30 50 per page