ChinaUnix.net
相关文章推荐:

python list过滤

[color="#00c600"]>>> [color="#0000ff"]import [color="#800000"]os [color="#00c600"]>>> [color="#0000ff"]import [color="#800000"]re [color="#00c600"]>>> [color="#000000"][m [color="#0000ff"]for [color="#000000"]m [color="#0000ff"]in [color="#808000"]dir[color="#000000"]([color="#800000"]os[color="#000000"]) [color="#0000ff"]if [color="#808000"]callable[color="#000000"]([color="#808000"]getat...

by wibrst - Python文档中心 - 2006-12-13 15:36:59 阅读(1255) 回复(0)

相关讨论

python的列表过滤 methodlist = [method for method in dir(object) if callable(getattr(object, method))] 如果了解shell的话,这个将很好理解: for method in dir(object) do if [ callable(getattr(object, method)) ];then print $method fi done 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/12592/showart_136385.html

by CUDev - Python文档中心 - 2006-07-04 18:45:59 阅读(1237) 回复(0)

python: list Comprehensions Note: Lines beginning with ">>>" and "..." indicate input to python (these are the default prompts of the interactive interpreter). Everything else is output from python. python supports a concept called "list comprehensions". It can be used to construct lists in a very natural, easy way, like a mathematician is used to do. The following are common ways to describe l...

by bigluo - Python文档中心 - 2009-05-31 16:16:24 阅读(2146) 回复(0)

python: How to Sort a list 很多时候,我们需要对list进行排序,python提供了两个方法 对给定的list L进行排序, 方法1.用list的成员函数sort进行排序 方法2.用built-in函数sorted进行排序(从2.4开始) 这两种方法使用起来差不多,以第一种为例进行讲解: 从python2.4开始,sort方法有了三个可选的参数,python Library Reference里是这样描述的 cmp:cmp specifies a custom comparison function of two arguments (iterable ele...

by WinNTApi - Python文档中心 - 2009-04-02 16:28:39 阅读(1882) 回复(0)

listpython是一种有顺序的、可变的类型,list的成员可以是任何一种python类型,甚至也包括 list,也就是list可以作为另一个list的成员。在list中,实际上保存的只是每一个成员对象的指针。在cpython中,list后台实现用 的就是c中的数组。 list的表示形式用的是一对中括号,成员用逗号隔开: [成员1, 成员2, 成员3...]由 于是list是有顺序的,因此list可以使用类似于string分片的方法访问list的成员。也可以用+进行连接,用*进行扩...

by marlboro027 - Python文档中心 - 2007-04-01 15:29:45 阅读(1115) 回复(0)

3.2.2. 向 list 中增加元素 例 3.10. 向 list 中增加元素 >>> li ['a', 'b', 'mpilgrim', 'z', 'example'] >>> li.append("new") >>> li ['a', 'b', 'mpilgrim', 'z', 'example', 'new'] >>> li.insert(2, "new") >>> li ['a', 'b', 'new', 'mpilgrim', 'z', 'example', 'new'] >>> li.extend(["two", "elements"]) >>> li ['a', 'b', 'new', 'mpilgrim', 'z', 'example', 'new', 'two', 'elements...

by CUDev - Python文档中心 - 2006-07-03 22:44:16 阅读(1539) 回复(0)

listpython是一种有顺序的、可变的类型,list的成员可以是任何一种python类型,甚至也包括list,也就是list可以作为另一个list的成员。在list中,实际上保存的只是每一个成员对象的指针。在cpython中,list后台实现用的就是c中的数组。 list的表示形式用的是一对中括号,成员用逗号隔开: [成员1, 成员2, 成员3...]由于是list是有顺序的,因此list可以使用类似于string分片的方法访问list的成员。也可以用+进行连接,用*进...

by newsim - Python文档中心 - 2006-02-24 16:55:39 阅读(1464) 回复(0)

我定义了如下list: a = [['',0]] * 5 然后我想对第一个list中的数字进行赋值。代码如下: a[0][1] = 5 当我打印a的时候发现所有的数字都改了。结果如下: >>> print a [['', 5], ['', 5], ['', 5], ['', 5], ['', 5]] 哪位大虾能否解释一下为什么. 如果我只想改第一个list的数值,怎么做? 谢谢 [ 本帖最后由 cs221313 于 2009-6-3 04:43 编辑 ]

by cs221313 - Python - 2009-06-04 09:20:30 阅读(3922) 回复(5)

python学习(2)-列表(list) 列表是一种序列,可以包含任意个python对象,与tuple和字符串不同的是它的元素是可以通过赋值修改的。 1、创建列表 #创建一个空列表 >>> a=[] >>> a [] >>> type(a) #创建一个列表的同时赋值 >>> a=['a','b'] >>> a ['a', 'b'] 2、访问列表 #用下标访问列表元素 >>> a[1] 'b' 3、修改列表元素 >>> a ['a', 'b'] >>> a[0]='c' >>> a ['c', 'b'] 4、删除列表元素和列表 #删除列表元素 >>> a ['c', 'b']...

by didonglin - Python文档中心 - 2009-04-28 13:20:59 阅读(1296) 回复(0)

#!/usr/bin/env python import xml.etree.ElementTree weblog = xml.etree.ElementTree.parse("C:\Script\modifyCfg\weblog.xml").getroot() print weblog aa = weblog.findall('entry') print aa for entry in weblog.findall("entry"): if entry.find('statusCode').text == '200': print entry interesting = [entry for entry in weblog.findall('entry') if entry....

by maojj - Python文档中心 - 2007-03-05 15:56:47 阅读(1245) 回复(0)

自己help(list)发现没有一个函数可以实现,查找某个变量在list的中,意思如下: >>>list=['apple','banana','orange','tomato'] >>>fruit='orange' 有没有一个函数能直接用来检测fruit是否在list中????、 谢谢。

by lemonniu - Python - 2008-09-26 13:03:18 阅读(2728) 回复(8)