码迷,mamicode.com
首页 >  
搜索关键字:def    ( 28626个结果
ruby Methods, Procs, Lambdas, and Closures
define simple method定义简单方法关键字def用于方法定义,在其后是方法名和可选的参数名列表,参数名列表会用一对圆括号括住。构成方法主体的代码放在参数列表之后,end用于结束方法定义。#define a methoddef factorial(n) if n0" ...
分类:其他好文   时间:2014-07-06 22:23:36    阅读次数:241
python的生成器
生成器>>> def func1():... yield 0... yield 1... >>> a=func1()>>> a.next()0>>> a.next()1>>> a.next()Traceback (most recent call last): File "", l...
分类:编程语言   时间:2014-07-06 20:07:34    阅读次数:251
【工作常用代码集】批量Telnet远端端口
作者:gnuhpc 出处:http://www.cnblogs.com/gnuhpc/ __author__ = 'gnuhpc'import telnetlib,socketIP={}def parseTel(line): parseArray = line.split() IP[parseArr...
分类:Web程序   时间:2014-07-06 18:19:01    阅读次数:321
递归00
00使用递归编写一个power()函数模拟内建函数pow(),即power(x, y)为计算并返回x的y次幂的值。def power(x,y): if y == 1: return x else: return x * power(x,y-1)number1 ...
分类:其他好文   时间:2014-07-06 17:55:37    阅读次数:334
递归01
00使用递归编写一个十进制转换为二进制的函数(要求采用“取2取余”的方式,结果与调用bin()一样返回字符串形式)。def Dec2bin(n): result = '' if n: result = Dec2bin(n//2) return resu...
分类:其他好文   时间:2014-07-06 15:18:57    阅读次数:306
Spark分析之Worker
override def preStart() { webUi = new WorkerWebUI(this, workDir, Some(webUiPort)) webUi.bind() //创建并绑定UI registerWithMaster() //注册到Master}d...
分类:其他好文   时间:2014-07-06 12:54:32    阅读次数:220
[leetcode] Insertion Sort List(python)
简单的插入排序,总是超时,暂且放在这记录一下。 class Solution: # @param head, a ListNode # @return a ListNode def insertionSortList(self, head): if head == None or head.next == None: return head psuhead...
分类:编程语言   时间:2014-07-06 11:52:20    阅读次数:230
【剑指offer】Q5:从尾到头打印链表
可以练习下链表的逆置。 def PrintListReversingly(head): if head == None: return if head: PrintListReversingly(head.next) print head.val def reverse(head): if head == None or head.next == None: return...
分类:其他好文   时间:2014-07-06 09:29:57    阅读次数:214
【leetcode】sort list(python)
链表的归并排序 超时的代码 class Solution: def merge(self, head1, head2): if head1 == None: return head2 if head2 == None: return head1 # head1 and head2 point to the same link list if head1 == he...
分类:编程语言   时间:2014-07-06 09:09:51    阅读次数:275
【剑指offer】Q6:重建二叉树
class BTNode: def __init__(self, val): self.left = None self.right = None self.val = val ''' @ construct tree by inorder & preorder ''' def constructByInPre(inorder, instart, inend, preorde...
分类:其他好文   时间:2014-07-06 00:34:00    阅读次数:234
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!