最近德甲英超西甲各大联赛重燃战火,想起之前写过的一段生成赛程表的代码,用python来写这类东西太舒服了. 这个算法叫做蛇环算法. 即,把所有球队排成一个环形(2列),左边对阵右边,第一支队伍不动,其他队伍顺时针循环,这样就肯定不重复了. 为了方便说明,假设有8支球队a到h.像下面那样按环形排好. a h | | b g | | c f | | d-e 这样,第1轮的对阵就是,(a,h)(b,g)(c,f)(d,e). 下一轮的时候,第一支球队a不动,其它球队像齿轮一样顺时针走一格
今天安装Python的模块时,安装失败,提示信息:Python version 2.7 required, which was not found in the registry. 原因在于Python在注册表中没有注册信息,需要手动添加: # # script to register Python 2.0 or later for use with win32all # and other extensions that require Python registry settings # #
转自:http://blog.csdn.net/u014680513/article/details/51005650 # script to register Python 2.0 or later for use with win32all# and other extensions that require Python registry settings## written by Joakim Loew for Secret Labs AB / PythonWare## source:#
def main(): names=['关羽','张飞','赵云','马超','貂蝉'] subjects=['语文','数学','Python'] table=[[0 for _ in range(3)] for _ in range(5)] #table=[[0]*len(subjects)]*len(names)这种写法为错误的 为同一引用 同一地址 #table[[0]*len(subjects) for_ in range (5)]这种写法为正确的 for row,name in en