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
47317090
Kaydet (Commit)
47317090
authored
Ock 17, 2008
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make starmap() match its pure python definition and accept any itertable input (not just tuples).
üst
3ad2acc8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
8 deletions
+15
-8
itertools.rst
Doc/library/itertools.rst
+6
-4
test_itertools.py
Lib/test/test_itertools.py
+2
-1
NEWS
Misc/NEWS
+3
-0
itertoolsmodule.c
Modules/itertoolsmodule.c
+4
-3
No files found.
Doc/library/itertools.rst
Dosyayı görüntüle @
47317090
...
...
@@ -330,17 +330,19 @@ loops that truncate the stream.
.. function:: starmap(function, iterable)
Make an iterator that computes the function using arguments
tuples
obtained from
Make an iterator that computes the function using arguments obtained from
the iterable. Used instead of :func:`imap` when argument parameters are already
grouped in tuples from a single iterable (the data has been "pre-zipped"). The
difference between :func:`imap` and :func:`starmap` parallels the distinction
between ``function(a,b)`` and ``function(*c)``. Equivalent to::
def starmap(function, iterable):
iterable = iter(iterable)
while True:
yield function(*iterable.next())
for args in iterable:
yield function(*args)
.. versionchanged:: 2.6
Previously, :func:`starmap` required the function arguments to be tuples.
Now, any iterable is allowed.
.. function:: takewhile(predicate, iterable)
...
...
Lib/test/test_itertools.py
Dosyayı görüntüle @
47317090
...
...
@@ -292,7 +292,8 @@ class TestBasicOps(unittest.TestCase):
self
.
assertEqual
(
take
(
3
,
starmap
(
operator
.
pow
,
izip
(
count
(),
count
(
1
)))),
[
0
**
1
,
1
**
2
,
2
**
3
])
self
.
assertEqual
(
list
(
starmap
(
operator
.
pow
,
[])),
[])
self
.
assertRaises
(
TypeError
,
list
,
starmap
(
operator
.
pow
,
[[
4
,
5
]]))
self
.
assertEqual
(
list
(
starmap
(
operator
.
pow
,
[
iter
([
4
,
5
])])),
[
4
**
5
])
self
.
assertRaises
(
TypeError
,
list
,
starmap
(
operator
.
pow
,
[
None
]))
self
.
assertRaises
(
TypeError
,
starmap
)
self
.
assertRaises
(
TypeError
,
starmap
,
operator
.
pow
,
[(
4
,
5
)],
'extra'
)
self
.
assertRaises
(
TypeError
,
starmap
(
10
,
[(
4
,
5
)])
.
next
)
...
...
Misc/NEWS
Dosyayı görüntüle @
47317090
...
...
@@ -993,6 +993,9 @@ Extension Modules
the context manager protocol. The _winreg module also gained a new function
``ExpandEnvironmentStrings`` to expand REG_EXPAND_SZ keys.
- itertools.starmap() now accepts any iterable input. Previously, it required
the function inputs to be tuples.
- Issue #1646: Make socket support TIPC. The socket module now has support
for TIPC under Linux, see http://tipc.sf.net/ for more information.
...
...
Modules/itertoolsmodule.c
Dosyayı görüntüle @
47317090
...
...
@@ -1356,10 +1356,11 @@ starmap_next(starmapobject *lz)
if
(
args
==
NULL
)
return
NULL
;
if
(
!
PyTuple_CheckExact
(
args
))
{
PyObject
*
newargs
=
PySequence_Tuple
(
args
);
Py_DECREF
(
args
);
PyErr_SetString
(
PyExc_TypeError
,
"iterator must return a tuple"
)
;
return
NULL
;
if
(
newargs
==
NULL
)
return
NULL
;
args
=
newargs
;
}
result
=
PyObject_Call
(
lz
->
func
,
args
,
NULL
);
Py_DECREF
(
args
);
...
...
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