距离上次写的博客,已经过去一个多礼拜了,这一个多礼拜主要是做了习题37--阅读别人的代码。在Github上搜了一个抢票软件,于是沉迷其中不可自拔。前段时间杰伦演唱会,闺蜜在永乐上想抢票却失败了,据说是瞬间没,伤心不已。朋友圈的黄牛党转手就是加价300卖,啧啧啧,暴利啊!!!为了行侠仗义,便想做一个抢票软件,等下次wuli谦谦的演唱会门票发售时,能一举拿下心仪之票。于是这一个礼拜都在鼓捣抢票软件了、、、惭愧的是,目前只能用代码实现自动打开浏览器,输入账号密码,验证码部分不能自动实现,仍需手动,停滞不前了。今天先接着往下学吧,说不定能有新发现。
习题39——列表的操作
老规矩,先贴代码,不能偷懒。
ten_things = "Apples Oranges Crows Telephone Light Sugar" print "Wait there's not 10 things in that list, lets fix that." stuff = ten_things.split(' ') more_stuff = ["Day", "Night", "Song", "Frisbee", "Corn", "Banana", "Girl", "Boy"] while len(stuff) != 10: next_one = more_stuff.pop() print "Adding: ", next_one stuff.append(next_one) print "There's %d item now." %len(stuff) print "There we go:", stuff print "Let's do some things with stuff." print stuff[1] print stuff[-1] print stuff.pop() print ' '.join(stuff) print '#'.join(stuff[3:5]) 这一个习题主要是对列表的操作,但是内容比较少,扩展一下应该至少包括四个方面:增删改查。dir()可以查看变量可调用的方法。在这里作者讲了一个有趣的事情,比如对于list L.split(' '),其实Python中应该是split(L,' '),翻译成自然语言就是为L和' '调用split函数。对于L.split(' '),翻译成自然语言应该是将L用' 'split开来。