![]() It's useful for splitting up the results of large data source. The groupby() function returns an iterator that produces sets of values organized by a common key. ![]() ![]() Ifilterfalse() returns an iterator that includes only items where the test func tion returns False. Ifilter() is different from dropwhile() in that every item is tested before it is returned. Ifilter() returns an iterator that works like the built-in filter() does for lists, including only items for which the test function returns True.įor i in ifilter(check_item, ): It returns an iterator that returns items from the input iterator, as long as the test function returns True. The opposite of dropwhile() is takewhile(). dropwhile() does not filter every item of the input after the condition is false the first time, all remaining items in the input are returned.įor i in dropwhile(should_drop, ): The dropwhile() function returns an iterator that produces elements of the input iterator after a condition becomes False for the first time. It works like the built-in map(), except that it stops when any input iterator is exhausted (instead of inserting None values to completely consume all inputs). The imap() function returns an iterator that calls a function on the values in the input iterators and returns the results. Returned by tee() can be used to feed the same set of data into multiple algorithms to be processed in parallel. The tee() function returns several independent iterators (defaults to 2) based on a single original input. Izip() returns an iterator that combines the elements of several iterators into tuples. The chain() function takes several iterators as arguments and returns a single iterator that produces the contents of all of them as though they came from a single iterator. The repeat() function returns an iterator that produces the same value each time it is accessed. Since it has to remember the entire contents of the input iterator, it may consume quite a bit of memory if the iterator is long.įor i, item in izip(xrange(7), cycle()): The cycle() function returns an iterator that indefinitely repeats the contents of the arguments it is given. The first number can be passed as an argument (the default is zero).įor i in izip(count(1), ): The count() function returns an iterator that produces consecutive integers, indefi- nitely. Since data is not produced from the iterator until it is needed, all data does not need to be stored in memory at the same time. Iterator-based code offers better memory consumption characteristics than code that uses lists. The itertools module includes a set of functions for working with sequence data sets.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |