以下で起こっていることを行うためのより効率的な方法はありますか? あると思いたいです。このスクリプトには特別な用途はありませんが、これを行うためのより効率的な方法を知っていると非常に便利です。
# Divides text into 10 lists.. you'll see what I mean.
# 5/21/2012
filename = "test.txt"
FILE = open(filename,"r")
# READ FILE WORD-BY-WORD:
f = open(filename,"r")
lines = f.readlines()
for i in lines:
thisline = i.split(" ")
FILE.close()
# DIVIDE INTO 10 LISTS:
list1 = []
list2 = []
list3 = []
list4 = []
list5 = []
list6 = []
list7 = []
list8 = []
list9 = []
list10 = []
j = 0
while j < len(thisline):
x = thisline[j]
list1.append(x)
j+=1
if j >= len(thisline):
break
x = thisline[j]
list2.append(x)
j+=1
if j >= len(thisline):
break
x = thisline[j]
list3.append(x)
j+=1
if j >= len(thisline):
break
x = thisline[j]
list4.append(x)
j+=1
if j >= len(thisline):
break
x = thisline[j]
list5.append(x)
j+=1
if j >= len(thisline):
break
x = thisline[j]
list6.append(x)
j+=1
if j >= len(thisline):
break
x = thisline[j]
list7.append(x)
j+=1
if j >= len(thisline):
break
x = thisline[j]
list8.append(x)
j+=1
if j >= len(thisline):
break
x = thisline[j]
list9.append(x)
j+=1
if j >= len(thisline):
break
x = thisline[j]
list10.append(x)
j+=1
if j >= len(thisline):
break
print "list 1 = "," ".join(list1)
print "list 2 = "," ".join(list2)
print "list 3 = "," ".join(list3)
print "list 4 = "," ".join(list4)
print "list 5 = "," ".join(list5)
print "list 6 = "," ".join(list6)
print "list 7 = "," ".join(list7)
print "list 8 = "," ".join(list8)
print "list 9 = "," ".join(list9)
print "list 10 = "," ".join(list10)
# EOF