On 2011-10-12 13:15, selahattin ay wrote:
hi all, I wrote these codes but the program must write the prints to a text
file...
code = [100, 200, 300, 400, 500]
list= []
a = 0
while a< 9:
a+=1
list.append(a)
last_list = [[int(str(i) + str(k)) for i in code] for k in list]
list2= []
b = 0
while b< 9:
b+=1
list2.append(b)
Others have already told you yesterday that you don't need while-loops:
list = range(1, 10)
list2 = list[:]
(you probably don't need "list2" at all)
the thing that I want to do is, I want to create text files from 1 to 9 as in
list2
1.txt, 2.txt ....9.txt like thatsample of a text file is :
X:CA
VERSION:2.5
P:(here will be the first value of list2 );;;;
L;C: (here will be the first value of last_list )
the first sample
X:CA
VERSION:2.5
P: 1 ;;;;
L;C: 1001
the first sample
X:CA
VERSION:2.5
P: 8 ;;;;
L;C: 1008
You want to write 9 files but last_list has 45 elements. What will
happen with the rest of them?
BTW: Your last_list is a list of 9 lists, each containing 5 elements
([[1001, 2001, ...], [1002, 2002, ...], ...]). Don't you really want a
list of 5 lists, each containing 9 elements ([[1001, 1002, ...], [2001,
2002, ...], ...])? At least I get this impression from your samples.
Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list