2005年06月07日 星期二 12:53
判断4个数或更多个数之中有没有相等的, 有为真,没有为假 可不可以用一条语句就表达, 或有没有现成的函数可用?
2005年06月06日 星期一 14:17
> 一段文本.将每个字母做为list一个元素??? > a='netkiller' > 我要得到是这样的 > ('n','e','t','k'......'e','r') tuple(a)
2005年06月07日 星期二 12:57
IF 'A' IN ('A','B'........) 看看这样用行不行??? Neo Chan Callsign: BG7NYT 73 -----Original Message----- From: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of fff 670 Sent: Tuesday, June 07, 2005 12:53 PM To: python-chinese at lists.python.cn Subject: [python-chinese] 如何最简的判断4个数之中有没有相等的数? 判断4个数或更多个数之中有没有相等的, 有为真,没有为假 可不可以用一条语句就表达, 或有没有现成的函数可用? -------------- next part -------------- A non-text attachment was scrubbed... Name: Neo Chan.vcf Type: text/x-vcard Size: 1081 bytes Desc: not available Url : http://lists.exoweb.net/pipermail/python-chinese/attachments/20050607/eab160a2/NeoChan.vcf
2005年06月07日 星期二 13:00
假如存放在一个容器中: a = [1, 2, 3, 3, 4] b = len(a) != len(set(a)) print b and "有相等的数" or "没有相等的数" 因为set会消除同等的数,所以通过长度判断就知道了。 fff 670 wrote: >判断4个数或更多个数之中有没有相等的, >有为真,没有为假 >可不可以用一条语句就表达, >或有没有现成的函数可用? > > >------------------------------------------------------------------------ > >_______________________________________________ >python-chinese list >python-chinese at lists.python.cn >http://python.cn/mailman/listinfo/python-chinese > >
2005年06月07日 星期二 13:07
这样可以,可要用到FOR遍历[A,B.....] 不知道有没有更简的方法?
2005年06月07日 星期二 13:15
如果要更进一步找出相等的数呢?
2005年06月07日 星期二 13:32
def unique (numbers): return len(set(numbers))==len(numbers) - ahbei ( http://blog.douban.com) On Jun 7, 2005, at 1:07 PM, fff 670 wrote: > 这样可以,可要用到FOR遍历[A,B.....] > 不知道有没有更简的方法? > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: text/enriched Size: 572 bytes Desc: not available Url : http://lists.exoweb.net/pipermail/python-chinese/attachments/20050607/4daf34f6/attachment.bin
2005年06月07日 星期二 13:37
:) 想到一起去了。 - ahbei (http://blog.douban.com) On Jun 7, 2005, at 1:00 PM, cpunion wrote: > 假如存放在一个容器中: > a = [1, 2, 3, 3, 4] > b = len(a) != len(set(a)) > print b and "有相等的数" or "没有相等的数" > > 因为set会消除同等的数,所以通过长度判断就知道了。 > > fff 670 wrote: > >> 判断4个数或更多个数之中有没有相等的, >> 有为真,没有为假 >> 可不可以用一条语句就表达, >> 或有没有现成的函数可用? >> >> ---------------------------------------------------------------------- >> -- >> >> _______________________________________________ >> python-chinese list >> python-chinese at lists.python.cn >> http://python.cn/mailman/listinfo/python-chinese >> > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: text/enriched Size: 1435 bytes Desc: not available Url : http://lists.exoweb.net/pipermail/python-chinese/attachments/20050607/7346b49d/attachment.bin
2005年06月07日 星期二 13:46
>>> a = [1, 2, 2, 3, 3, 4, 5, 6, 6, 7] >>> b = set(a) >>> a [1, 2, 2, 3, 3, 4, 5, 6, 6, 7] >>> b set([1, 2, 3, 4, 5, 6, 7]) >>> c = [i for i in a if i not in b or b.remove(i) and False] >>> c [2, 3, 6] 哈哈,用set效率应该还不算低吧,remove应该也比较快的,如果你自己用循环查 找而没有排序,我相信没有set快。 fff 670 wrote: >如果要更进一步找出相等的数呢? > > >------------------------------------------------------------------------ > >_______________________________________________ >python-chinese list >python-chinese at lists.python.cn >http://python.cn/mailman/listinfo/python-chinese > >
2005年06月07日 星期二 13:47
Skipped content of type multipart/alternative-------------- next part -------------- A non-text attachment was scrubbed... Name: Neo Chan.vcf Type: text/x-vcard Size: 1081 bytes Desc: not available Url : http://lists.exoweb.net/pipermail/python-chinese/attachments/20050607/d5a238d8/NeoChan-0001.vcf
2005年06月07日 星期二 13:49
哦,set的remove方法没有返回值,所以后面的and False可以去掉: c = [i for i in a if i not in b or b.remove(i)] cpunion wrote: > >>> a = [1, 2, 2, 3, 3, 4, 5, 6, 6, 7] > >>> b = set(a) > >>> a > [1, 2, 2, 3, 3, 4, 5, 6, 6, 7] > >>> b > set([1, 2, 3, 4, 5, 6, 7]) > >>> c = [i for i in a if i not in b or b.remove(i) and False] > >>> c > [2, 3, 6] > > 哈哈,用set效率应该还不算低吧,remove应该也比较快的,如果你自己用循环 > 查 找而没有排序,我相信没有set快。 > > fff 670 wrote: > >> 如果要更进一步找出相等的数呢? >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> python-chinese list >> python-chinese at lists.python.cn >> http://python.cn/mailman/listinfo/python-chinese >> >> >
2005年06月07日 星期二 14:01
fff 670 wrote: > 如果要更进一步找出相等的数呢? [x for x in set(a) if a.count(x) > 1] -- Qiangning Hong _____________________________________________________________ / It is impossible to travel faster than light, and certainly \ | not desirable, as one's hat keeps blowing off. | | | \ -- Woody Allen / ------------------------------------------------------------- \ ^__^ \ ($$)\_______ ________ (__)\ )\/\ |Super | ||----W | |Milker| || UDDDDDDDDD|______|
2005年06月07日 星期二 14:18
hehe,你行,上课先.
2005年06月07日 星期二 14:22
直接a[0],a[1]就可以取出里面的元素了 2005/6/7, Neo Chan (netkiller) <neo.chen at achievo.com>: > > 一段文本.将每个字母做为list一个元素??? > a='netkiller' > 我要得到是这样的 > ('n','e','t','k'......'e','r') > > > Neo Chan > Callsign: BG7NYT > 73 > > > ________________________________ > From: python-chinese-bounces at lists.python.cn > [mailto:python-chinese-bounces at lists.python.cn] On Behalf > Of Bo Yang > Sent: Tuesday, June 07, 2005 1:33 PM > To: python-chinese at lists.python.cn > Subject: Re: [python-chinese] 如何最简的判断4个数之中有没有相等的数? > > > def unique (numbers): > return len(set(numbers))==len(numbers) > > > - ahbei > ( http://blog.douban.com) > > On Jun 7, 2005, at 1:07 PM, fff 670 wrote: > > > 这样可以,可要用到FOR遍历[A,B.....] > 不知道有没有更简的方法? > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > > -- Blog:http://www.donews.net/changzheng
2005年06月07日 星期二 14:23
参考这段程序看看,limodou写的: 对标准输入文件做以下工作 1,统计字符总数(包括空白,TAB等) 2,统计行数 3,统计单词数(每个单词由SPACE,TAB或换行分开) import sys body=sys.stdin.read() print "total charters is %d" % len(body) lines=body.splitlines() print "total lines is %d" % len(lines) words=body.split() print "total words is %d" % len(words) 可能有帮助.
2005年06月07日 星期二 14:25
>>> a='netkiller' >>> list(a) ['n', 'e', 't', 'k', 'i', 'l', 'l', 'e', 'r'] 不明白??直接不就有了阿 ----- Original Message ----- From: Neo Chan (netkiller) To: python-chinese at lists.python.cn Sent: Tuesday, June 07, 2005 1:47 PM Subject: [python-chinese] 急问一个问题. 一段文本.将每个字母做为list一个元素??? a='netkiller' 我要得到是这样的 ('n','e','t','k'......'e','r') Neo Chan Callsign: BG7NYT 73 ------------------------------------------------------------------------------ From: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of Bo Yang Sent: Tuesday, June 07, 2005 1:33 PM To: python-chinese at lists.python.cn Subject: Re: [python-chinese] 如何最简的判断4个数之中有没有相等的数? def unique (numbers): return len(set(numbers))==len(numbers) - ahbei ( http://blog.douban.com) On Jun 7, 2005, at 1:07 PM, fff 670 wrote: 这样可以,可要用到FOR遍历[A,B.....] 不知道有没有更简的方法? _______________________________________________ python-chinese list python-chinese at lists.python.cn http://python.cn/mailman/listinfo/python-chinese ------------------------------------------------------------------------------ _______________________________________________ python-chinese list python-chinese at lists.python.cn http://python.cn/mailman/listinfo/python-chinese -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050607/604219a5/attachment.htm
2005年06月07日 星期二 14:37
我用 for print 输出,print自动在后右加\r\n 我如何处理.我想在一行输出. Neo Chan Callsign: BG7NYT 73 -------------- next part -------------- A non-text attachment was scrubbed... Name: Neo Chan.vcf Type: text/x-vcard Size: 1081 bytes Desc: not available Url : http://lists.exoweb.net/pipermail/python-chinese/attachments/20050607/dc5c5ab5/NeoChan-0001.vcf
2005年06月07日 星期二 14:59
谢谢,就是一层窗纸.哈哈... Neo Chan Callsign: BG7NYT 73 -----Original Message----- From: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of Petr ?imon Sent: Monday, June 06, 2005 2:17 PM To: python-chinese at lists.python.cn Subject: Re: [python-chinese] 急问一个问题. > 一段文本.将每个字母做为list一个元素??? > a='netkiller' > 我要得到是这样的 > ('n','e','t','k'......'e','r') tuple(a) -------------- next part -------------- A non-text attachment was scrubbed... Name: Neo Chan.vcf Type: text/x-vcard Size: 1081 bytes Desc: not available Url : http://lists.exoweb.net/pipermail/python-chinese/attachments/20050607/fb1115e0/NeoChan.vcf
2005年06月07日 星期二 15:08
#the Morse code #author: neo.chan(at)achievo.com import string import time import winsound class Morse: mcode = '' def __init__(self): pass # def __init__(self, frequency, duration): def beep(self,sound): for code in sound: if code == 0: # di self.mcode = self.mcode + '.' winsound.Beep( 400, 100) elif code == 1: # da self.mcode = self.mcode + '_' winsound.Beep( 400, 300) else: break self.mcode = self.mcode + ' ' winsound.Beep( 37, 150) #print repr(mcode) def reader(self,char): for code in char: #print repr(code) self.mcode = code + ' : ' code = string.upper(code) if code == '1': self.beep((0,1,1,1,1)) if code == '2': self.beep((0,0,1,1,1)) if code == '3': self.beep((0,0,0,1,1)) if code == '4': self.beep((0,0,0,0,1)) if code == '5': self.beep((0,0,0,0,0)) if code == '6': self.beep((1,0,0,0,0)) if code == '7': self.beep((1,1,0,0,0)) if code == '8': self.beep((1,1,1,0,0)) if code == '9': self.beep((1,1,1,1,0)) if code == '0': self.beep((0,0,0,0,0)) if code == 'A': self.beep((0,1)) if code == 'B': self.beep((1,0,0,0)) if code == 'C': self.beep((1,0,1,0)) if code == 'D': self.beep((1,0,0)) if code == 'E': self.beep((0,)) if code == 'F': self.beep((0,0,1,0)) if code == 'G': self.beep((1,1,0)) if code == 'H': self.beep((0,0,0,0)) if code == 'I': self.beep((0,0)) if code == 'J': self.beep((0,1,1,1)) if code == 'K': self.beep((1,0,1)) if code == 'L': self.beep((0,1,0,0)) if code == 'M': self.beep((1,1)) if code == 'N': self.beep((1,0)) if code == 'O': self.beep((1,1,1)) if code == 'P': self.beep((0,1,1,0)) if code == 'Q': self.beep((1,1,0,1)) if code == 'R': self.beep((0,1,0)) if code == 'S': self.beep((0,0,0)) if code == 'T': self.beep((1,)) if code == 'U': self.beep((0,0,1)) if code == 'V': self.beep((0,0,0,1)) if code == 'W': self.beep((0,1,1)) if code == 'X': self.beep((1,0,0,1)) if code == 'Y': self.beep((1,0,1,1)) if code == 'Z': self.beep((1,1,0,0)) if code == '?': self.beep((0,0,1,1,0,0)) if code == '/': self.beep((1,0,0,1,0)) if code == '(': self.beep((1,0,1,1,0,1)) if code == ')': self.beep((1,0,0,0,0)) if code == '-': self.beep((1,0,0,0,0,1)) if code == '.': self.beep((0,1,0,1,0,1)) #.--.-. if code == '@': self.beep((0,1,1,0,1,0)) print self.mcode time.sleep(0.5) """ def doc2list(self,doc): tmp = []; for n in range(len(doc)): tmp.append(doc[n]) #print doc[n] return tmp """ #Main Program doc = """ Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms. """ def main(): cw = Morse() #cw.beep((0,1,0,0,1,1,1)) #cw.reader(('a','b','c','d','e')) #print cw.doc2list('netkiller') cw.reader(tuple(doc)) if __name__ == '__main__': main() Neo Chan Callsign: BG7NYT 73 -------------- next part -------------- A non-text attachment was scrubbed... Name: Neo Chan.vcf Type: text/x-vcard Size: 1081 bytes Desc: not available Url : http://lists.exoweb.net/pipermail/python-chinese/attachments/20050607/b000850b/NeoChan.vcf
2005年06月07日 星期二 15:21
Skipped content of type multipart/alternative-------------- next part -------------- A non-text attachment was scrubbed... Name: Neo Chan.vcf Type: text/x-vcard Size: 1081 bytes Desc: not available Url : http://lists.exoweb.net/pipermail/python-chinese/attachments/20050607/1529bb24/NeoChan.vcf
2005年06月07日 星期二 15:31
Neo Chan (netkiller) wrote: > 一段文本.将每个字母做为list一个元素??? > a='netkiller' > 我要得到是这样的 > ('n','e','t','k'......'e','r') > > > Neo Chan > Callsign: BG7NYT > 73 真奇怪,我20分钟前就收到了好几封对你这个问题的回答,怎么现在才收到原贴呢? -- Qiangning Hong ___________________________________________________________ ( The little pieces of my life I give to you, with love, to ) ( make a quilt to keep away the cold. ) ----------------------------------------------------------- o o ___ {~._.~} ( Y ) ()~*~() (_)-(_)
Zeuux © 2025
京ICP备05028076号