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循环 ...
随机推荐
- mysql的主从配置以及主主配置
基础环境 系统:linuxmysql版本:5.5主服务器IP:192.168.1.101从服务器IP:192.168.1.102 1.主服务器(master)要打开二进制日志2.从服务器(slave) ...
- 【sql】之使用sql根据身份证查询过生日人数
根据当前日期查询有多少人过生日 ,) = DATE_FORMAT(NOW(),'%m'); 查询price一样的人数 select * from people where price in (sele ...
- [svn]svn merge
转:http://blog.csdn.net/keda8997110/article/details/21813035 Step by Step 完成merge 目录: Branch的必要性 1.本地 ...
- python使用xlrd模块读写Excel文件的方法
本文实例讲述了python使用xlrd模块读写Excel文件的方法.分享给大家供大家参考.具体如下: 一.安装xlrd模块 到python官网下载http://pypi.python.org/pypi ...
- 一. JVM发展史,运行时数据区域,四大引用
一.JVM的出现 JVM将字节码解释成不同os下的机器指令,有了jvm,java语言在不同平台上运行时不需要重新编译 虚拟机发展史 (1)Sun Classic classic jvm要么采用纯解释器 ...
- Tomcat插件与Jetty插件在MyEclipse中的配置
-Djetty.port=8101 jetty:run tomcat6:run <plugin> <groupId>org.apache.tomcat.maven</gr ...
- RMAN_学习实验1_RMAN备份标准过程(案例)
2014-12-23 Created By BaoXinjian
- poj_2485_mst
Highways Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit St ...
- Hibernae 的延迟加载
http://blog.csdn.net/xc635960736/article/details/7049863 Hibernae 的延迟加载 Hibernae 的延迟加载是一个非常常用的技术,实 ...
- c语言知识(2)
while(n)首先,n在这里被当作了一个条件其次,当n为真时,进入while循环体(A):否则跳出循环继续执行下面部分(B).n为0时条件为假 n不为0条件为真 while(j) { if(j%1 ...