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循环 ...
随机推荐
- SSH登录很慢问题的解决
用ssh连其他linux机器,会等待10-30秒才有提示输入密码.严重影响工作效率.登录很慢,登录上去后速度正常,这种情况主要有两种可能的原因: 1. DNS反向解析的问题 OpenSSH在用户登录的 ...
- elasticsearch2
简单认为是可以在命令行下访问url的一个工具 curl是利用URL语法在命令行方式下工作的开源文件传输工具,使用curl可以简单实现常见的get/post请求. curl -x 指定http请求的方法 ...
- ADF_Starting系列2_使用ADF开发富Web应用程序之建立Business Services
2013-05-01 Created By BaoXinjian
- 0808HTML
打开DREAMWEAVER,新建HTML,页面上有几句代码 <html>开始标签 <head>网页上的控制信息 <title>页面标题</title> ...
- 实现从sql server存取二进制图片
转:http://www.cnblogs.com/jeffwongishandsome/archive/2009/08/27/1554440.html 1.存取图片(1).将图片文件转换为二进制并直接 ...
- yuv422/yuv420格式
关于YUV格式 转载:http://www.cnblogs.com/soniclq/archive/2012/02/02/2335974.html YUV 格式通常有两大类:打包(packed)格式和 ...
- ibatis插入数据后返回自增长的主键
insert into testTable ( activity_id,activity_title values ( #{activityId,jdbcType=INTEGER}, #{activi ...
- mat(Eclipse Memory Analyzer tool)之二--heap dump分析
文章中的shallow.retained关键字的说明见:GC是如何回收时的判断依据.shallow size.retained size 在本文中,将介绍MAT(Eclipse Memory Anal ...
- bootstrap-响应式工具和打印样式
响应式工具: <div class="container"> <!-- 针对不同的宽度 展示或隐藏相关内容 visible-lg-block 显示 hidden- ...
- 在asp.net 中应用POST传递和接收XML文件以及参数.(转)
使用POST方式可以向别的页面发送请求,并获取返回结果. 可以从一个页面发送POST到另一个页面,也可以在winform工程中使用HTTPRequest发送POST到一个页面.我们拿ASP.NET的a ...