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
c7095843
Kaydet (Commit)
c7095843
authored
Nis 14, 2006
tarafından
Andrew M. Kuchling
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add more items
üst
984bdd75
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
10 deletions
+70
-10
whatsnew25.tex
Doc/whatsnew/whatsnew25.tex
+70
-10
No files found.
Doc/whatsnew/whatsnew25.tex
Dosyayı görüntüle @
c7095843
...
@@ -857,10 +857,29 @@ language.
...
@@ -857,10 +857,29 @@ language.
\begin{itemize}
\begin{itemize}
\item
The
\class
{
dict
}
type has a new hook for letting subclasses
provide a default value when a key isn't contained in the dictionary.
When a key isn't found, the dictionary's
\method
{__
missing
__
(
\var
{
key
}
)
}
method will be called. This hook is used to implement
the new
\class
{
defaultdict
}
class in the
\module
{
collections
}
module. The following example defines a dictionary
that returns zero for any missing key:
\begin{verbatim}
class zerodict (dict):
def
__
missing
__
(self, key):
return 0
d = zerodict(
{
1:1, 2:2
}
)
print d[1], d[2] # Prints 1, 2
print d[3], d[4] # Prints 0, 0
\end{verbatim}
\item
The
\function
{
min()
}
and
\function
{
max()
}
built-in functions
\item
The
\function
{
min()
}
and
\function
{
max()
}
built-in functions
gained a
\code
{
key
}
keyword argument analogous to the
\code
{
key
}
gained a
\code
{
key
}
keyword argument analogous to the
\code
{
key
}
argument for
\method
{
sort()
}
. This argument supplies a function
argument for
\method
{
sort()
}
. This argument supplies a function
that
t
hat takes a single argument and is called for every value in the list;
t
akes a single argument and is called for every value in the list;
\function
{
min()
}
/
\function
{
max()
}
will return the element with the
\function
{
min()
}
/
\function
{
max()
}
will return the element with the
smallest/largest return value from this function.
smallest/largest return value from this function.
For example, to find the longest string in a list, you can do:
For example, to find the longest string in a list, you can do:
...
@@ -903,8 +922,6 @@ class C():
...
@@ -903,8 +922,6 @@ class C():
\end{verbatim}
\end{verbatim}
(Implemented by Brett Cannon.)
(Implemented by Brett Cannon.)
% XXX __missing__ hook in dictionaries
\end{itemize}
\end{itemize}
...
@@ -964,9 +981,6 @@ details.
...
@@ -964,9 +981,6 @@ details.
\begin{itemize}
\begin{itemize}
% XXX collections.deque now has .remove()
% collections.defaultdict
% the cPickle module no longer accepts the deprecated None option in the
% the cPickle module no longer accepts the deprecated None option in the
% args tuple returned by __reduce__().
% args tuple returned by __reduce__().
...
@@ -984,6 +998,55 @@ details.
...
@@ -984,6 +998,55 @@ details.
and the code for u-LAW encoding has been improved. (Contributed by
and the code for u-LAW encoding has been improved. (Contributed by
Lars Immisch.)
Lars Immisch.)
\item
The
\module
{
collections
}
module gained a new type,
\class
{
defaultdict
}
, that subclasses the standard
\class
{
dict
}
type. The new type mostly behaves like a dictionary but constructs a
default value when a key isn't present, automatically adding it to the
dictionary for the requested key value.
The first argument to
\class
{
defaultdict
}
's constructor is a factory
function that gets called whenever a key is requested but not found.
This factory function receives no arguments, so you can use built-in
type constructors such as
\function
{
list()
}
or
\function
{
int()
}
. For
example,
you can make an index of words based on their initial letter like this:
\begin{verbatim}
words = """Nel mezzo del cammin di nostra vita
mi ritrovai per una selva oscura
che la diritta via era smarrita""".lower().split()
index = defaultdict(list)
for w in words:
init
_
letter = w[0]
index[init
_
letter].append(w)
\end{verbatim}
Printing
\code
{
index
}
results in the following output:
\begin{verbatim}
defaultdict(<type 'list'>,
{
'c': ['cammin', 'che'], 'e': ['era'],
'd': ['del', 'di', 'diritta'], 'm': ['mezzo', 'mi'],
'l': ['la'], 'o': ['oscura'], 'n': ['nel', 'nostra'],
'p': ['per'], 's': ['selva', 'smarrita'],
'r': ['ritrovai'], 'u': ['una'], 'v': ['vita', 'via']
}
\end{verbatim}
The
\class
{
deque
}
double-ended queue type supplied by the
\module
{
collections
}
module now has a
\method
{
remove(
\var
{
value
}
)
}
method that removes the first occurrence of
\var
{
value
}
in the queue,
raising
\exception
{
ValueError
}
if the value isn't found.
\item
The
\module
{
cProfile
}
module is a C implementation of
the existing
\module
{
profile
}
module that has much lower overhead.
The module's interface is the same as
\module
{
profile
}
: you run
\code
{
cProfile.run('main()')
}
to profile a function, can save profile
data to a file, etc. It's not yet known if the Hotshot profiler,
which is also written in C but doesn't match the
\module
{
profile
}
module's interface, will continue to be maintained in future versions
of Python. (Contributed by Armin Rigo.)
\item
In the
\module
{
gc
}
module, the new
\function
{
get
_
count()
}
function
\item
In the
\module
{
gc
}
module, the new
\function
{
get
_
count()
}
function
returns a 3-tuple containing the current collection counts for the
returns a 3-tuple containing the current collection counts for the
three GC generations. This is accounting information for the garbage
three GC generations. This is accounting information for the garbage
...
@@ -1141,9 +1204,6 @@ by some specifications, so it's still available as
...
@@ -1141,9 +1204,6 @@ by some specifications, so it's still available as
%======================================================================
%======================================================================
% whole new modules get described in subsections here
% whole new modules get described in subsections here
%======================================================================
%\subsection{The cProfile module}
%======================================================================
%======================================================================
\subsection
{
The ctypes package
}
\subsection
{
The ctypes package
}
...
...
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