【Python】Learn Python the hard way, ex38 列表操作

来源:互联网 发布:仓储出库数据流程图 编辑:程序博客网 时间:2024/06/07 07:59
ten_things = "Apples Oranges Crows Telephone Light Sugar"print "Wait there's not 10  things in that list, let's 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 items now." %len(stuff)    print "There we go: ", stuffprint "Let's do some things with stuff."print stuff[1]print stuff[-1] #whoa! fancyprint stuff.pop()print " ".join(stuff) # what? cool!print '#'.join(stuff[3:5])  #supper stellar!'''Test Reslut:Wait there's not 10  things in that list, let's fix that.Adding:  BoyThere's 7 items now.Adding:  GirlThere's 8 items now.Adding:  BananaThere's 9 items now.Adding:  CornThere's 10 items now.There we go:  ['Apples', 'Oranges', 'Crows', 'Telephone', 'Light', 'Sugar', 'Boy', 'Girl', 'Banana', 'Corn']Let's do some things with stuff.OrangesCornCornApples Oranges Crows Telephone Light Sugar Boy Girl BananaTelephone#Light'''


最喜欢Python两点,list,re


0 0
原创粉丝点击