November 13th, 2012, 05:40 PM
A little help with understanding counters
Hi i was wondering if we have a file that we looped through line by line looking like this:
And we want to make a list of list of string out of this..
How do we make a counter for this to reset.
What type of if condition would we use.
So for example our function looks like this:
result = 
---sub_result = 
---for next_line in file:
--- ---if __________________:
--- ---- ---- result.append(next_line)
--- --- ---- sub_result.append(next_line/ next_ekement)
Basically my question is that, the new sublist begins when the next line hits an empty line...i wanna know a way to make it so.. perhaps a counter that restarts everytime a blank line appears?
>>> word_list(open("file.txt", "r"))
[['Hello', 'Hi', 'Bonjour'], ['Bye', 'Aurovoir', 'Bye Bye']]
Something like this..
November 13th, 2012, 08:59 PM
We already answered this in post 6.
[/code] are essential for python code and Makefiles!
November 13th, 2012, 09:16 PM
i know.. But it didnt really do anything.
I dont really want the solved code and i am aware that my code didnt have a return function, but its because i was going to fix that later on.
I just want someone to help me with the counters.
Do we even need a counter for this is my question. Also, if we do, then to restart it, we would need to set it to 0 right?
if sub_list == ['\n']:
counter == 0
This will restart the function if i am right, but i just want someone to explain it to me.