2007年06月12日 星期二 23:36
假设有三个区间:(1,100),(101,300),(301,999) 给定一个整数n,请问有什么简便有效的方法可以判断n落在哪个区间内呢?
2007年06月12日 星期二 23:49
1£¬100£¬101£¬300£¬301£¬999²ÉÓÃ2·Ö·¨£¬ºÙºÙ¡£ ÔÚ07-6-12£¬Shuning Hong <hongshuning在gmail.com> дµÀ£º > > ¼ÙÉèÓÐÈý¸öÇø¼ä£º£¨1£¬100£©£¬£¨101£¬300£©£¬(301,999) > ¸ø¶¨Ò»¸öÕûÊýn£¬ÇëÎÊÓÐʲô¼ò±ãÓÐЧµÄ·½·¨¿ÉÒÔÅжÏnÂäÔÚÄĸöÇø¼äÄÚÄØ£¿ > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070612/6ff3ddff/attachment.htm
2007年06月13日 星期三 00:04
On 6/12/07, Shuning Hong <hongshuning在gmail.com> wrote: > 假设有三个区间:(1,100),(101,300),(301,999) > 给定一个整数n,请问有什么简便有效的方法可以判断n落在哪个区间内呢? a= 112 In [4]: a in range(300,400) ...: Out[4]: False In [5]: a in range(101,300) ...: Out[5]: True > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -- '''Time is unimportant, only life important! http://zoomquiet.org blog在http://blog.zoomquiet.org/pyblosxom/ wiki在http://wiki.woodpecker.org.cn/moin/ZoomQuiet scrap在http://floss.zoomquiet.org douban在http://www.douban.com/people/zoomq/ ____________________________________ Pls. use OpenOffice.org to replace M$ Office. http://zh.openoffice.org Pls. use 7-zip to replace WinRAR/WinZip. http://7-zip.org/zh-cn/ You can get the truely Freedom 4 software. '''
2007年06月13日 星期三 01:03
import bisect r = bisect.bisect([1,101,301,1000], n) if r == 1: print (1, 100) elif r == 2: print (101, 300) elif r == 3: print (301, 999) -------------- ä¸ä¸é¨å -------------- ??HTML?????... URL: http://python.cn/pipermail/python-chinese/attachments/20070613/85d25e1e/attachment.html
2007年06月13日 星期三 09:20
>>> l = [[1, 100], [101, 300], [301, 999]] >>> def locate(v, l): ... for x in l: ... if ( v>=x[0] and v<=x[1]): ... return x ... >>> locate(30, l) [1, 100] >>> locate(300, l) [101, 300] >>> locate(305, l) [301, 999] 个人以为pan的方法不错. 2007/6/13, pan <nirvana117 at gmail.com>: > > import bisect > > r = bisect.bisect([1,101,301,1000], n) > > if r == 1: > print (1, 100) > elif r == 2: > print (101, 300) > elif r == 3: > print (301, 999) > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- 努力做好每一件事 TRY TO DO MY BEST -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20070613/6347a8fa/attachment-0001.html
2007年06月13日 星期三 09:23
On 6/13/07, 东子/hydon <hydonlee在gmail.com> wrote: > >>> l = [[1, 100], [101, 300], [301, 999]] > >>> def locate(v, l): > ... for x in l: > ... if ( v>=x[0] and v<=x[1]): > ... return x > ... 在python中,v>=x[0] and v<=x[1]可以写成x[0] <= v <= x[1] -- Best Regards, Leo Jay
Zeuux © 2025
京ICP备05028076号