[issue27751] Itertools -> Recipes -> pairwise()

2016-08-12 Thread Tim Peters

Changes by Tim Peters :


--
resolution:  -> rejected
stage:  -> resolved

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27751] Itertools -> Recipes -> pairwise()

2016-08-12 Thread YoSTEALTH

YoSTEALTH added the comment:

Tim, I get what you are saying good point.

--
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27751] Itertools -> Recipes -> pairwise()

2016-08-12 Thread Tim Peters

Tim Peters added the comment:

Note that "iterable" covers a world of things that may not support indexing 
(let alone slicing).  For example, it may be a generator, or a file open for 
reading.

--
nosy: +tim.peters

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27751] Itertools -> Recipes -> pairwise()

2016-08-12 Thread YoSTEALTH

New submission from YoSTEALTH:

# Link: https://docs.python.org/3/library/itertools.html#itertools-recipes
# Function pairwise() in Itertools -> Recipes could be improved!? Here is the 
code:


import time
import itertools


def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = itertools.tee(iterable)
next(b, None)
return zip(a, b)


def new_pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
return zip(iterable, iterable[1:])


combine = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)


if __name__ == '__main__':
start_time = time.time()

# Current
print('Current:')
print(list(pairwise(combine)))
# output: [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), 
(8, 9)]

print()

# New
print('New:')
print(list(new_pairwise(combine)))
# output: [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), 
(8, 9)]

# Benchmark
# for _ in range(100):
# list(pairwise(combine))  # Time: 2.61199975
# list(new_pairwise(combine))  # Time: 1.14828038

print('\n\nTime: {}'.format(round(time.time() - start_time, 8)), end='')

--
messages: 272572
nosy: YoSTEALTH
priority: normal
severity: normal
status: open
title: Itertools -> Recipes -> pairwise()
type: performance
versions: Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com