Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add islice function to python program?

I am trying to use the islice function but am getting the following error:

Traceback (most recent call last):
  File "/Users/gavinnachbar/Session 3 copy/all_in_one_almost.py", line 168, in <module>
    all_decisions.extend(islice(reader,4))
NameError: name 'islice' is not defined

I have imported itertools but am still getting the error, any idea why?

like image 757
user2512696 Avatar asked Oct 20 '25 13:10

user2512696


1 Answers

... because you are trying to import iterator, which does not exist?

Edit:

Have you tried either

from itertools import islice

or

all_decisions.extend(itertools.islice(reader,4))
like image 200
Hugh Bothwell Avatar answered Oct 23 '25 02:10

Hugh Bothwell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!