python - Navigating Callable-Iterators -


I want to use regular expressions to extract information from some chat logs. The format of the strings has been parsed 03:22:32 PM . I used it to use the Python Type () command that variable messages are a callable-iterator. My question is how can I navigate with the most efficient means of caller-Iterator? Are they like arrays where you can just use an index? The only way to remove the data was to loop through the returned values ​​and to add them to the list shown in the code snippet below.

  times = [] messages = again .compile (r '(? P>; time & gt; ..: ..: .. ..). *? & Lt; b & Gt; (? P & lt; usrname & gt;. *?): & Lt; / b & gt; '). Search) for results in message: times.append (result.group ('time')) Is there a better and effective way of doing this? Thanks for the help.   

An Iterator is an object with a next method. Every time you call it, it returns the next item in a collection. If you need to arbitrarily index, then you have to convert it to a list. Instead: For results in the message

 : times.append (result.group ('time'))  

You can say: <

This is very much the same thing. However, I should warn you that doing this for a large result set will be very slow and will eat a bunch of memory. Thus, you should not do this if you do not need random access. If an untrusted user enters, it will determine how many results will appear, you can limit the number of things they can enter.

Edit : I have just seen that my previous answer was not the same as the snippet you posted, so I updated it.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -