3 ms·
I don't disagree with the main point, but Python already has quite a bit of this. A more pythonic version of the first example: @retry(DOWNLOAD_TRIES)
by yummyfajitas 12y ago
I don't disagree with the main point, but Python already has quite a bit of this. A more pythonic version of the first example:
@retry(DOWNLOAD_TRIES)
def download(url):
...
images = [download(u) for u in urls]
To check if a sequence x is ascending, you can use standard library functions:
all( t[1] > t[0] for t in zip(x[0:-1], x[1:]) )
- Suor 12y agoJust zip(seq, seq[1:]) Won't work with iterator though.
- andreasvc 12y agoitertools.islice would work.
- Suor 12y agoNo it won't, unless you `tee` an iterator first.
- e12e 12y agoFYI, the official documentation of itertools has its very own pairwise example: def pairwise(iterable): "s -> (s0,s1), (s1,s2), (s2, s3), ..." a, b = tee(iterable) next(b, None) return izip(a, b) https://docs.python.org/2/library/itertools.html#itertools.izip https://docs.python.org/2/library/itertools.html#itertools.i...
- baq 12y agofor the record: the official itertools docs have a lot more examples than this one and they're all really worth knowing about if not studying.
- e12e 12y agoIndeed: all(a < b for a,b in zip(seq,seq[1:])) (Although one might want <= if checking to see if the sequence is sorted, rather than strictly ascending (that is, it can contain matching/repeated elements)).