Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
5 votes
1 answer
2k views

Writing a lazy-evaluation dataclass [closed]

I have a dataclass which is frequently used but is slow because as it processes multiple large datasets. I have tried to speed it up by making it lazily-evaluate, where the data is only read when ...
tgpz's user avatar
  • 69
5 votes
0 answers
208 views

@lazylist - Converts a Python Generator to a List without evaluating every element

Inspired by a blog I read, I made a LazyList class that can wrap an iterable (list, generator etc.) and turn it into a ...
Greedo's user avatar
  • 2,625
8 votes
4 answers
608 views

Lazy generator of strings in lexicographical order

I needed to write a Python generator that lazily generates, in lexicographical order, strings composed of a certain alphabet (e.g. lowercase English letters). My first thought was to make an infinite ...
Anakhand's user avatar
  • 645
1 vote
1 answer
1k views

Lazy evaluation function decorator

Suppose I have some expensive function expensive_computation which takes a long time to compute but it always returns the same value. I want to avoid paying the ...
cglacet's user avatar
  • 243
1 vote
1 answer
334 views

Lazy prime counting function [closed]

I have written a simple snippet of code that implements a function that returns a list of primes up to a certain integer n. Assuming that this function could be ...
Anakhand's user avatar
  • 645
9 votes
2 answers
3k views

Lazy split and semi-lazy split

Sometimes I need to be able to split data into chunks, and so something like str.split would be helpful. This comes with two downsides: Input has to be strings You ...
Peilonrayz's user avatar
  • 44.3k
3 votes
1 answer
89 views

Python JIT container type

This is a follow on from this review. Where I am attempting to improve the performance of my rest client. I have created an container type (as suggested in my previous post) that lazily instantiates ...
James Schinner's user avatar
3 votes
1 answer
299 views

Efficiently determine every factor of a given natural number

It's not hard to find all of the factors of a given natural number. Below is a pretty fast python function that can do just that: (Modified version of Steinar Lima's function, https://stackoverflow....
Will Da Silva's user avatar
1 vote
1 answer
89 views

Class to help dealing with files, with lazy properties

I have the following class to help me deal with files: File class: ...
user avatar
6 votes
2 answers
2k views

Python lazy dict with iterator in constructor

This question began as an off-topic answer to this question, but the code here serves a different goal. I wrote the following class for the purpose of populating a dict on demand from an iterator. ...
Eirik Fuller's user avatar
3 votes
1 answer
4k views

Python lazy dictionary

Here is a lazy dictionary with test cases. ...
Justin Fay's user avatar
2 votes
2 answers
188 views

Lazy properties for the angle and length of a line segment

The code below shows the pattern I use to manage properties in my classes when I have the following requirements: Some properties are slow to calculate and are rarely used, so I want them to be lazy ...
stenci's user avatar
  • 135
6 votes
2 answers
2k views

Recursive flatten with lazy evaluation iterator

I'm trying to rewrite this: ...
LetMeSOThat4U's user avatar
3 votes
2 answers
3k views

Lazy class instantiation in Python

I've written some class which allows me to derive from it to make objects lazy-instantiated. Do you see notational improvements or maybe even cases where this method might not work (multiple ...
Gere's user avatar
  • 143