简体   繁体   中英

Want to confirm the meaning of the name islice in Python itertools.islice

I'm new in Python and I'm not an English native speaker. Today I learned some functions in the itertools module. There is a function called islice. Does it stand for infinitive slice ? As I understand it can be used to slice infinitive sequence of objects and is commonly used with itertools.count() .

I presume it stands for "iterable slice", since it takes the same arguments as the slice built-in but generates a sequence of results rather than returning a list.

You may be suffering from some slight misunderstanding of "infinitive," which is a part of speech (in English, "to fall" is the infinitive of the verb "fall"). You perhaps mean "infinite," which is never-ending or uncountable.

If so, you have correctly observed that one advantage of the functions in itertools is that they can be applied to infinite sequences. This is because they return iterators that yield results on demand, rather than functions that return lists.

slice is a built-in class. The prefix 'i' for 'iterator' is added to avoid confusion and a name clash if one does from itertools import * .

In Python 2, itertools also had imap and ifilter , to avoid clashing with the old versions of map and filter . In Python 3, imap and ifilter became the new versions of map and filter and were hence removed from itertools .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM