Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
96ef8115
Kaydet (Commit)
96ef8115
authored
Şub 01, 2003
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Move itertools module from the sandbox and into production.
üst
506be287
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
170 additions
and
0 deletions
+170
-0
lib.tex
Doc/lib/lib.tex
+1
-0
libitertools.tex
Doc/lib/libitertools.tex
+0
-0
test_itertools.py
Lib/test/test_itertools.py
+158
-0
NEWS
Misc/NEWS
+3
-0
itertoolsmodule.c
Modules/itertoolsmodule.c
+0
-0
config.c
PC/config.c
+2
-0
pythoncore.dsp
PCbuild/pythoncore.dsp
+4
-0
setup.py
setup.py
+2
-0
No files found.
Doc/lib/lib.tex
Dosyayı görüntüle @
96ef8115
...
@@ -125,6 +125,7 @@ and how to embed it in other applications.
...
@@ -125,6 +125,7 @@ and how to embed it in other applications.
\input
{
libheapq
}
\input
{
libheapq
}
\input
{
libarray
}
\input
{
libarray
}
\input
{
libsets
}
\input
{
libsets
}
\input
{
libitertools
}
\input
{
libcfgparser
}
\input
{
libcfgparser
}
\input
{
libfileinput
}
\input
{
libfileinput
}
\input
{
libxreadlines
}
\input
{
libxreadlines
}
...
...
Doc/lib/libitertools.tex
0 → 100644
Dosyayı görüntüle @
96ef8115
This diff is collapsed.
Click to expand it.
Lib/test/test_itertools.py
0 → 100644
Dosyayı görüntüle @
96ef8115
import
unittest
from
test
import
test_support
from
itertools
import
*
class
TestBasicOps
(
unittest
.
TestCase
):
def
test_count
(
self
):
self
.
assertEqual
(
zip
(
'abc'
,
count
()),
[(
'a'
,
0
),
(
'b'
,
1
),
(
'c'
,
2
)])
self
.
assertEqual
(
zip
(
'abc'
,
count
(
3
)),
[(
'a'
,
3
),
(
'b'
,
4
),
(
'c'
,
5
)])
self
.
assertRaises
(
TypeError
,
count
,
2
,
3
)
def
test_ifilter
(
self
):
def
isEven
(
x
):
return
x
%
2
==
0
self
.
assertEqual
(
list
(
ifilter
(
isEven
,
range
(
6
))),
[
0
,
2
,
4
])
self
.
assertEqual
(
list
(
ifilter
(
isEven
,
range
(
6
),
True
)),
[
1
,
3
,
5
])
self
.
assertEqual
(
list
(
ifilter
(
None
,
[
0
,
1
,
0
,
2
,
0
])),
[
1
,
2
])
self
.
assertRaises
(
TypeError
,
ifilter
)
self
.
assertRaises
(
TypeError
,
ifilter
,
3
)
self
.
assertRaises
(
TypeError
,
ifilter
,
isEven
,
3
)
self
.
assertRaises
(
TypeError
,
ifilter
,
isEven
,
[
3
],
True
,
4
)
def
test_izip
(
self
):
ans
=
[(
x
,
y
)
for
x
,
y
in
izip
(
'abc'
,
count
())]
self
.
assertEqual
(
ans
,
[(
'a'
,
0
),
(
'b'
,
1
),
(
'c'
,
2
)])
self
.
assertRaises
(
TypeError
,
izip
)
def
test_repeat
(
self
):
self
.
assertEqual
(
zip
(
xrange
(
3
),
repeat
(
'a'
)),
[(
0
,
'a'
),
(
1
,
'a'
),
(
2
,
'a'
)])
self
.
assertRaises
(
TypeError
,
repeat
)
def
test_times
(
self
):
self
.
assertEqual
(
list
(
times
(
3
)),
[
None
]
*
3
)
self
.
assertEqual
(
list
(
times
(
3
,
True
)),
[
True
]
*
3
)
self
.
assertRaises
(
ValueError
,
times
,
-
1
)
def
test_imap
(
self
):
import
operator
self
.
assertEqual
(
list
(
imap
(
operator
.
pow
,
range
(
3
),
range
(
1
,
7
))),
[
0
**
1
,
1
**
2
,
2
**
3
])
self
.
assertEqual
(
list
(
imap
(
None
,
'abc'
,
range
(
5
))),
[(
'a'
,
0
),(
'b'
,
1
),(
'c'
,
2
)])
self
.
assertRaises
(
TypeError
,
imap
)
self
.
assertRaises
(
TypeError
,
imap
,
operator
.
neg
)
def
test_starmap
(
self
):
import
operator
self
.
assertEqual
(
list
(
starmap
(
operator
.
pow
,
zip
(
range
(
3
),
range
(
1
,
7
)))),
[
0
**
1
,
1
**
2
,
2
**
3
])
def
test_islice
(
self
):
for
args
in
[
# islice(args) should agree with range(args)
(
10
,
20
,
3
),
(
10
,
3
,
20
),
(
10
,
20
),
(
10
,
3
),
(
20
,)
]:
self
.
assertEqual
(
list
(
islice
(
xrange
(
100
),
*
args
)),
range
(
*
args
))
for
args
,
tgtargs
in
[
# Stop when seqn is exhausted
((
10
,
110
,
3
),
((
10
,
100
,
3
))),
((
10
,
110
),
((
10
,
100
))),
((
110
,),
(
100
,))
]:
self
.
assertEqual
(
list
(
islice
(
xrange
(
100
),
*
args
)),
range
(
*
tgtargs
))
self
.
assertRaises
(
TypeError
,
islice
,
xrange
(
10
))
self
.
assertRaises
(
TypeError
,
islice
,
xrange
(
10
),
1
,
2
,
3
,
4
)
self
.
assertRaises
(
ValueError
,
islice
,
xrange
(
10
),
-
5
,
10
,
1
)
self
.
assertRaises
(
ValueError
,
islice
,
xrange
(
10
),
1
,
-
5
,
-
1
)
self
.
assertRaises
(
ValueError
,
islice
,
xrange
(
10
),
1
,
10
,
-
1
)
self
.
assertRaises
(
ValueError
,
islice
,
xrange
(
10
),
1
,
10
,
0
)
def
test_takewhile
(
self
):
data
=
[
1
,
3
,
5
,
20
,
2
,
4
,
6
,
8
]
underten
=
lambda
x
:
x
<
10
self
.
assertEqual
(
list
(
takewhile
(
underten
,
data
)),
[
1
,
3
,
5
])
def
test_dropwhile
(
self
):
data
=
[
1
,
3
,
5
,
20
,
2
,
4
,
6
,
8
]
underten
=
lambda
x
:
x
<
10
self
.
assertEqual
(
list
(
dropwhile
(
underten
,
data
)),
[
20
,
2
,
4
,
6
,
8
])
libreftest
=
""" Doctest for examples in the library reference, libitertools.tex
>>> for i in times(3):
... print "Hello"
...
Hello
Hello
Hello
>>> amounts = [120.15, 764.05, 823.14]
>>> for checknum, amount in izip(count(1200), amounts):
... print 'Check
%
d is for $
%.2
f'
%
(checknum, amount)
...
Check 1200 is for $120.15
Check 1201 is for $764.05
Check 1202 is for $823.14
>>> import operator
>>> import operator
>>> for cube in imap(operator.pow, xrange(1,4), repeat(3)):
... print cube
...
1
8
27
>>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele']
>>> for name in islice(reportlines, 3, len(reportlines), 2):
... print name.title()
...
Alex
Laura
Martin
Walter
Samuele
>>> def enumerate(iterable):
... return izip(count(), iterable)
>>> def tabulate(function):
... "Return function(0), function(1), ..."
... return imap(function, count())
>>> def iteritems(mapping):
... return izip(mapping.iterkeys(), mapping.itervalues())
>>> def nth(iterable, n):
... "Returns the nth item"
... return islice(iterable, n, n+1).next()
"""
__test__
=
{
'libreftest'
:
libreftest
}
def
test_main
(
verbose
=
None
):
import
test_itertools
suite
=
unittest
.
TestSuite
()
for
testclass
in
(
TestBasicOps
,
):
suite
.
addTest
(
unittest
.
makeSuite
(
testclass
))
test_support
.
run_suite
(
suite
)
test_support
.
run_doctest
(
test_itertools
,
verbose
)
# verify reference counting
import
sys
if
verbose
and
hasattr
(
sys
,
"gettotalrefcount"
):
counts
=
[]
for
i
in
xrange
(
5
):
test_support
.
run_suite
(
suite
)
counts
.
append
(
sys
.
gettotalrefcount
())
print
counts
if
__name__
==
"__main__"
:
test_main
(
verbose
=
True
)
Misc/NEWS
Dosyayı görüntüle @
96ef8115
...
@@ -30,6 +30,9 @@ Core and builtins
...
@@ -30,6 +30,9 @@ Core and builtins
Extension modules
Extension modules
-----------------
-----------------
- Added an itertools module containing high speed, memory efficient
looping constructs inspired by tools from Haskell and SML.
- The SSL module now handles sockets with a timeout set correctly (SF
- The SSL module now handles sockets with a timeout set correctly (SF
patch #675750, fixing SF bug #675552).
patch #675750, fixing SF bug #675552).
...
...
Modules/itertoolsmodule.c
0 → 100644
Dosyayı görüntüle @
96ef8115
This diff is collapsed.
Click to expand it.
PC/config.c
Dosyayı görüntüle @
96ef8115
...
@@ -45,6 +45,7 @@ extern void init_hotshot(void);
...
@@ -45,6 +45,7 @@ extern void init_hotshot(void);
extern
void
initxxsubtype
(
void
);
extern
void
initxxsubtype
(
void
);
extern
void
initzipimport
(
void
);
extern
void
initzipimport
(
void
);
extern
void
init_random
(
void
);
extern
void
init_random
(
void
);
extern
void
inititertools
(
void
);
/* XXX tim: what's the purpose of ADDMODULE MARKER? */
/* XXX tim: what's the purpose of ADDMODULE MARKER? */
/* -- ADDMODULE MARKER 1 -- */
/* -- ADDMODULE MARKER 1 -- */
...
@@ -97,6 +98,7 @@ struct _inittab _PyImport_Inittab[] = {
...
@@ -97,6 +98,7 @@ struct _inittab _PyImport_Inittab[] = {
{
"_weakref"
,
init_weakref
},
{
"_weakref"
,
init_weakref
},
{
"_hotshot"
,
init_hotshot
},
{
"_hotshot"
,
init_hotshot
},
{
"_random"
,
init_random
},
{
"_random"
,
init_random
},
{
"itertools"
,
inititertools
},
{
"xxsubtype"
,
initxxsubtype
},
{
"xxsubtype"
,
initxxsubtype
},
{
"zipimport"
,
initzipimport
},
{
"zipimport"
,
initzipimport
},
...
...
PCbuild/pythoncore.dsp
Dosyayı görüntüle @
96ef8115
...
@@ -323,6 +323,10 @@ SOURCE=..\Objects\iterobject.c
...
@@ -323,6 +323,10 @@ SOURCE=..\Objects\iterobject.c
# End Source File
# End Source File
# Begin Source File
# Begin Source File
SOURCE=..\Modules\itertoolsmodule.c
# End Source File
# Begin Source File
SOURCE=..\Parser\listnode.c
SOURCE=..\Parser\listnode.c
# End Source File
# End Source File
# Begin Source File
# Begin Source File
...
...
setup.py
Dosyayı görüntüle @
96ef8115
...
@@ -324,6 +324,8 @@ class PyBuildExt(build_ext):
...
@@ -324,6 +324,8 @@ class PyBuildExt(build_ext):
libraries
=
math_libs
)
)
libraries
=
math_libs
)
)
# random number generator implemented in C
# random number generator implemented in C
exts
.
append
(
Extension
(
"_random"
,
[
"_randommodule.c"
])
)
exts
.
append
(
Extension
(
"_random"
,
[
"_randommodule.c"
])
)
# fast iterator tools implemented in C
exts
.
append
(
Extension
(
"itertools"
,
[
"itertoolsmodule.c"
])
)
# operator.add() and similar goodies
# operator.add() and similar goodies
exts
.
append
(
Extension
(
'operator'
,
[
'operator.c'
])
)
exts
.
append
(
Extension
(
'operator'
,
[
'operator.c'
])
)
# Python C API test module
# Python C API test module
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment