Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9ea23ce

Browse files
committed
Adding __eq__ to Card
1 parent fb6404e commit 9ea23ce

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

book/book.tex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
\title{Think Python}
3434
\author{Allen B. Downey}
3535
\newcommand{\thetitle}{Think Python: How to Think Like a Computer Scientist}
36-
\newcommand{\theversion}{2nd Edition, Version 2.2.14}
36+
\newcommand{\theversion}{2nd Edition, Version 2.2.15}
3737
\newcommand{\thedate}{}
3838

3939
% these styles get translated in CSS for the HTML version
@@ -8291,6 +8291,8 @@ \section{Debugging}
82918291
82928292
In this example you could also use the built-in function {\tt sorted},
82938293
which returns a new, sorted list and leaves the original alone.
8294+
\index{sorted!function}
8295+
\index{function!sorted}
82948296
82958297
\begin{verbatim}
82968298
>>> t2 = sorted(t)
@@ -8857,8 +8859,8 @@ \section{Looping and dictionaries}
88578859
%
88588860
Again, the keys are in no particular order. To traverse the keys
88598861
in sorted order, you can use the built-in function {\tt sorted}:
8860-
\index{keys method}
8861-
\index{method!keys}
8862+
\index{sorted!function}
8863+
\index{function!sorted}
88628864
88638865
\begin{verbatim}
88648866
>>> for key in sorted(h):
@@ -10791,7 +10793,7 @@ \section{Dictionary subtraction}
1079110793
diff = subtract(hist, words)
1079210794
1079310795
print("Words in the book that aren't in the word list:")
10794-
for word in diff.keys():
10796+
for word in diff:
1079510797
print(word, end=' ')
1079610798
\end{verbatim}
1079710799
%

code/Card.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ def __str__(self):
3535
return '%s of %s' % (Card.rank_names[self.rank],
3636
Card.suit_names[self.suit])
3737

38+
def __eq__(self, other):
39+
"""Checks whether self and other have the same rank and suit.
40+
41+
returns: boolean
42+
"""
43+
return self.suit == other.suit and self.rank == other.rank
44+
3845
def __lt__(self, other):
3946
"""Compares this card to other, first by suit, then rank.
4047

code/Card_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""This file contains code for use with "Think Stats",
2+
by Allen B. Downey, available from greenteapress.com
3+
4+
Copyright 2014 Allen B. Downey
5+
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
6+
"""
7+
8+
from __future__ import print_function, division
9+
10+
import unittest
11+
from Card import Card, Deck
12+
13+
14+
class Test(unittest.TestCase):
15+
16+
def testDeckRemove(self):
17+
deck = Deck()
18+
card23 = Card(2, 3)
19+
deck.remove_card(card23)
20+
21+
22+
if __name__ == "__main__":
23+
unittest.main()

0 commit comments

Comments
 (0)