Add, remove, shuffle and sort
To deal cards, we would like a method that removes a card from the deck and returns it. The list method pop provides a convenient way to do that. Since pop removes the last card in the list, we are in effect dealing from the bottom of the deck. To add a card, we can use the list method append. As another example, we can write a Deck method named shuffle using the function shuffle from the random module.
def pop_card(self):
return self.cards.pop() def add_card(self,card):
return self.cards.append(card) def shuffle(self):
random.shuffle(self.cards) def sort(self):
for i in range(len(self.cards)):
for j in range(i+1,len(self.cards)):
if(self.cards[i].cmp(self.cards[j])>0):
self.cards[i],self.cards[j] = self.cards[j],self.cards[i]
A method like this that uses another function without doing much real work is sometimes called a veneer, the metaphor comes from woodworking, where it is common to glue a thin layer of good quality wood to the surface of a cheaper piece of wood.
from Thinking in Python
Add, remove, shuffle and sort的更多相关文章
- Partitioning, Shuffle and sort
Partitioning, Shuffle and sort what happened? - Partitioning Partitioning is the process of determi ...
- WIX: Hide installed program from the Add/Remove Programs window.
Reference article : How to hide an entry in the Add/Remove Programs applet? In Wix source files, set ...
- How to hide an entry in the Add/Remove Programs applet?
Original link: http://www.winhelponline.com/articles/15/1/How-to-hide-an-entry-in-the-AddRemove-Prog ...
- Hadoop-2.2.0中文文档—— MapReduce下一代- 可插入的 Shuffle 和 Sort
简单介绍 可插入的 shuffle 和 sort 功能,同意在shuffle 和 sort 逻辑中用可选择的实现类替换.这个情况的样例是:用一个不是HTTP的应用协议,如RDMA来 shuffle 从 ...
- Maste Note for OCR / Vote disk Maintenance Operations (ADD/REMOVE/REPLACE/MOVE)
Doc ID 428681.1 Applies to: Oracle Database - Enterprise Edition - Version 10.2.0.1 to 11.2.0.1.0 [R ...
- shuffle和sort分析
MapReduce中的Shuffle和Sort分析 MapReduce 是现今一个非常流行的分布式计算框架,它被设计用于并行计算海量数据.第一个提出该技术框架的是Google 公司,而Google 的 ...
- mapreduce shuffle 和sort 详解
MapReduce 框架的核心步骤主要分两部分:Map 和Reduce.当你向MapReduce 框架提交一个计算作业时,它会首先把计算作业拆分成若干个Map 任务,然后分配到不同的节点上去执 ...
- MapReduce中的Shuffle和Sort分析
MapReduce 是现今一个非常流行的分布式计算框架,它被设计用于并行计算海量数据.第一个提出该技术框架的是Google 公司,而Google 的灵感则来自于函数式编程语言,如LISP,Scheme ...
- 有关集合的foreach循环里的add/remove
转自:Hollis(微信号:hollischuang) 在阿里巴巴Java开发手册中,有这样一条规定: 但是手册中并没有给出具体原因,本文就来深入分析一下该规定背后的思考. 1 .foreach循环 ...
随机推荐
- bzoj3034: Heaven Cow与God Bull
Description __int64 ago,there's a heaven cow called sjy...A god bull named wzc fell in love with her ...
- httpd安装
1.软件准备 http://apache.fayea.com/apache-mirror//apr/apr-1.5.1.tar.gz http://apache.fayea.com/apache-mi ...
- BeX5学习笔记
1.[窗口]——[首选项]中,有数据源等其它信息的设置,如下所示:
- (PowerShell) Managing Windows Registry
http://powershell.com/cs/blogs/ebookv2/archive/2012/03/23/chapter-16-managing-windows-registry.aspx
- Git-Flow
Overview Git-Flow is a high-level command set wrapping low-level Git commands to support the "s ...
- OAF_架构MVC系列3 - View的概述(概念)
2014-06-18 Created By BaoXinjian
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
题是看了这位的博客之后理解的,只不过我是又加了点简单的注释. 链接:http://blog.csdn.net/chinaczy/article/details/5890768 我还加了一些注释代码,对 ...
- poj_2421_mst
D - Constructing Roads Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- 加密--win7下安装openssl
http://www.cnblogs.com/ZhouL3777/archive/2012/10/21/2732890.html http://www.cnblogs.com/ZhouL3777/ar ...
- 【转】H264编码原理以及I帧B帧P帧
前言 H264是新一代的编码标准,以高压缩高质量和支持多种网络的流媒体传输著称,在编码方面,我理解的他的理论依据是:参照一段时间内图像的统计结果表明,在相邻几幅图像画面中,一般有差别的像素只有10%以 ...