View Single Post
Old Dec 10th, 2005, 4:40 PM   #8
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by UnKnown X
Yet another question: How would I make it write the line number next to the fibonacci number, and then ignore it (the line number)?
I.e:
1: 1
2: 1
3: 2
4: 3
5: 5
6: 8
7: 13
8: 21
9: 34
...
I'm not quite sure what you mean. Is the above "code" meant as input from a file, or output from your python program?

To output it, you can use the enumerate function, which encodes a running count into any sequence:
for number, line in enumerate(file):
   print "%d: %s" % (number, line),
To input it, you can use the split function, which divides a string based on a specified delimiting character:
for line in file:
   number, data = line.split(":")
Arevos is offline   Reply With Quote