{"id":313584,"date":"2020-11-23T03:00:20","date_gmt":"2020-11-23T03:00:20","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=313584"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=313584","title":{"rendered":"Itertools \u0432 Python"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<blockquote>\n<p><strong>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 <\/strong><a href=\"https:\/\/otus.pw\/Btqm\/\"><strong>&#171;Python Developer. Basic&#187;<\/strong><\/a>.<\/p>\n<\/blockquote>\n<hr>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c <code>itertools<\/code> \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0431\u044b\u0441\u0442\u0440\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u0441\u0430\u043c\u0438 \u043f\u043e \u0441\u0435\u0431\u0435 \u0438\u043b\u0438 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438. \u0412\u043c\u0435\u0441\u0442\u0435 \u043e\u043d\u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442 \u00ab\u0430\u043b\u0433\u0435\u0431\u0440\u0443 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432\u00bb, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u043c Python.<\/p>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c itertools \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Python.<\/p>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0438\u043f\u044b \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432:&nbsp;<\/p>\n<ul>\n<li>\n<p>\u0411\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b;<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b;<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u043d\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043f\u043e \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e:<\/p>\n<ul>\n<li>\n<p>\u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>\u00abnext\u00bb<\/code><\/p>\n<\/li>\n<li>\n<p>\u0446\u0438\u043a\u043b\u0430 <code>for<\/code><\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>list()<\/code><\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0411\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b:<\/strong><\/p>\n<p><code>count()<\/code><em>, <\/em><code>cycle()<\/code><em>, <\/em><code>repeat()<\/code><\/p>\n<\/p>\n<p>1. <code>count()<\/code><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0447\u0438\u0441\u043b\u0430, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435 <em>start<\/em>. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <em>start<\/em> \u0440\u0430\u0432\u0435\u043d 0, \u0430 <em>step<\/em> -1. \u0428\u0430\u0433 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0446\u0435\u043b\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440.<\/p>\n<pre><code class=\"python\">import itertools c=itertools.count() #next() function returns next item in the iterator.By default starts with number 0 and increments by 1. print (next(c))#Output:0 print (next(c))#Output:1 print (next(c))#Output:2 print (next(c))#Output:3   #Returns an infinite iterator starting with number 5 and incremented by 10. The values in the iterator are accessed by next() c1=itertools.count(5,10) print(next(c1))#Output:5 print(next(c1))#Output:10 print(next(c1))#Output:15   #accessing values in the iterator using for loop.step argument can be float values also. c2=itertools.count(2.5,2.5) for i in c2:     #including terminating condition, else loop will keep on going.(infinite loop)     if i&gt;25:         break     else:         print (i,end=\" \") #Output:2.5 5.0 7.5 10.0 12.5 15.0 17.5 20.0 22.5 25.0           #step can be negative numbers also.negative numbers count backwards. c3=itertools.count(2,-2.5) print (next(c3))#Output:2 print (next(c3))#Output:-0.5 print (next(c3))#Output:-3.0<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 <code>map()<\/code> \u0438 <code>zip()<\/code>.<\/p>\n<p><code>zip()<\/code><em> <\/em>\u2013 \u044d\u0442\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f Python, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 <em>zip<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439. <code>itertools.count()<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>zip()<\/code>.<\/p>\n<pre><code class=\"python\">import itertools #itertools.count() used in zip() l1=[5,15,25] l2=zip(itertools.count(),l1) #It will return zip object which is an iterable instance of zip class print (l2)#Output:&lt;zip object at 0x032C92C8&gt;   #we can convert zip object to list. print (list(l2))#Output:[(0, 5), (1, 15), (2, 25)]   # We can access the zip object by using \"for loop\".This is more efficient way to access large sequences.It won't be memory intensive. l3=zip(itertools.count(),l1) for i in l3:     print (i) ''' Output: (0, 5) (1, 15) (2, 25) '''<\/code><\/pre>\n<\/p>\n<p><code>map()<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e \u0432\u0441\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u0432 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0435 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 <em>map<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>itertools.count()<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>map()<\/code>.<\/p>\n<pre><code class=\"python\">import itertools #lambda function and itertools.count() is given as argument in map()function. l1=map(lambda x:x**2,itertools.count()) #It returns a map object which is an iterator. print(l1)#Output:&lt;map object at 0x00E2E610&gt;  #iterate thorugh map object using for loop for i in l1:     if i&gt;50:         break     else:         print (i ,end=\" \")#Output:0 1 4 9 16 25 36 49<\/code><\/pre>\n<p>2.<em> <\/em><code>cycle()<\/code><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0449\u0438\u0439 \u043a\u043e\u043f\u0438\u044e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445. \u041a\u043e\u0433\u0434\u0430 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043f\u0438\u0438. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e.<\/p>\n<p><code>itertools.cycle(iterable)<\/code><\/p>\n<pre><code class=\"python\">import itertools l1=[1,2,3] #using list iterable as an argument in itertools.cycle() l2=itertools.cycle(l1) print (l2)#Output:&lt;itertools.cycle object at 0x02F794E8&gt;  count=0 for i in l2:     #It will end in infinite loop. So have to define terminating condition.     if count &gt; 15:         break     else:         print (i,end=\" \")#Output:1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1         count+=1           #string is given as an argument in itertools.cycle() function. s1=\"hello\" l3=itertools.cycle(s1) #accessing the iterator using next() print (next(l3))#Output:h print (next(l3))#Output:e print (next(l3))#Output:l print (next(l3))#Output:l print (next(l3))#Output:o<\/code><\/pre>\n<\/p>\n<p>3.<em> <\/em><code>repeat()<\/code>:<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043d\u043e\u0432\u0430 \u0438 \u0441\u043d\u043e\u0432\u0430. \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 <code>times<\/code>.<\/p>\n<p>\u041c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 <code>map()<\/code> \u0438 <code>zip()<\/code>.<\/p>\n<p><code>itertools.repeat(object,times)<\/code><\/p>\n<pre><code class=\"python\">import itertools #times argument is not mentioned. It will result in infinite loop. l1=itertools.repeat(2) print (next(l1))#Output:2 print (next(l1))#Output:2   #string is used as an argument.times argument is mentioned as 10.It will repeat the string 10 times. l2=itertools.repeat(\"hello\",times=10) for i in l2:     print (i,end=\" \")#Output:hello hello hello hello hello hello hello hello hello hello print (\" \")   #list is used as argument l3=itertools.repeat([1,2,3],times=3) for i in l3:     print (i,end=\" \")#Output:[1, 2, 3] [1, 2, 3] [1, 2, 3] print (\" \")   #tuple is used as an argument l4=itertools.repeat(('red','blue'),times=3) for i in l4:     print (i,end=\" \")#Output:('red', 'blue') ('red', 'blue') ('red', 'blue')<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>map()<\/code>.<\/p>\n<pre><code class=\"python\">import itertools #It will return square of numbers from 0 to 9. l1=map(pow,range(10),itertools.repeat(2)) print(l1)#Output:&lt;map object at 0x011CEC10&gt;  #iterate through map object using for loop for i in l1:     print (i,end=\" \") #Output:0 1 4 9 16 25 36 49 64 81<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>zip()<\/code>.<\/p>\n<pre><code class=\"python\">import itertools #itertools.repeat() used in zip() l1=[5,15,25] l2=zip(itertools.repeat(2),l1) #It will return zip object which is an iterable instance of zip class print (l2)#Output:&lt;zip object at 0x032794E8&gt;   #we can convert zip object to list. print (list(l2))#Output:[(2, 5), (2, 15), (2, 25)]   # We can access zip object by using for loop.This is more efficient way to access large sequences.It won't be memory intensive. l3=zip(itertools.repeat(\"hello\"),l1) for i in l3:     print (i) ''' Output: ('hello', 5) ('hello', 15) ('hello', 25) '''<\/code><\/pre>\n<p><strong>\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b:<\/strong><\/p>\n<\/p>\n<p>1<em>.<\/em><code>accumulate()<\/code><em>:<\/em><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u0438\u043b\u0438 \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 <em>func<\/em>.&nbsp;<\/p>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <em>initial<\/em>, \u043e\u043d \u0442\u0430\u043a\u0436\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u0445\u043e\u0434\u043d\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0430 \u043e\u0434\u0438\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0432\u0445\u043e\u0434\u043d\u0430\u044f.&nbsp;<\/p>\n<p><code>functools.reduce()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.&nbsp;<\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440<code> initial<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0432 <em>Python \u0432\u0435\u0440\u0441\u0438\u0438 3.8.<\/em><\/p>\n<p><code>itertools.accumulate(iterable,func,*,initial=None)<\/code><\/p>\n<pre><code class=\"python\">import itertools #using add and mul operator,so importing operator module import operator #using reduce(),so importing reduce() from functools module from functools import reduce  #If func parameter is not mentioned,by default it will perform addition operation) l1=itertools.accumulate([1,2,3,4,5]) print (l1)#Output:&lt;itertools.accumulate object at 0x02CD94C8&gt; #Converting iterator to list object. print (list(l1))#Output:[1, 3, 6, 10, 15] #using reduce() for same function r1=reduce(operator.add,[1,2,3,4,5]) print (r1)#Output:15   #If initial parameter is mentioned, it will start accumulating from the initial value. #It will contain more than one element in the ouptut iterable. l2=itertools.accumulate([1,2,3,4,5],operator.add,initial=10) print (list(l2))#Output:[10, 11, 13, 16, 20, 25]   #it takes operator mul as function # It will perform multiplication on first two elements, then it will perform multiplication of next two element in the iterable. l3=itertools.accumulate([1,2,3,5,5],operator.mul) print (list(l3))#Output:[1, 2, 6, 30, 150] #using reduce() for same function mul. r2=reduce(operator.mul,[1,2,3,4,5]) print (r2)#Output:120   l4=itertools.accumulate([2,4,6,3,1],max) print (list(l4))#Output:[2, 4, 6, 6, 6] #using reduce for same function max r3=reduce(max,[2,4,6,3,1]) print (r3)#Output:6   #It takes min function as parameter. # It will compare two elements and find the minimum element,then compare the other elements and find the mininum element. l5=itertools.accumulate([2,4,6,3,1],min) print (list(l5))#Output:[2, 2, 2, 2, 1] #using reduce() for same function min r4=reduce(min,[2,4,6,3,1]) print (r4)#Output:1<\/code><\/pre>\n<\/p>\n<p>2.<em> <\/em><code>chain()<\/code><em>:<\/em><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043e\u043d \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0438\u0434\u0443\u0449\u0438\u0435 \u0434\u0440\u0443\u0433 \u0437\u0430 \u0434\u0440\u0443\u0433\u043e\u043c, \u043a\u0430\u043a \u043e\u0434\u043d\u0443.&nbsp;<\/p>\n<p><code>itertools.chain(*iterables)<\/code><\/p>\n<pre><code class=\"python\">import itertools l1=itertools.chain([\"red\",\"blue\"],[1,2,3],\"hello\") #Returns an iterator object print (l1)#Output:&lt;itertools.chain object at 0x029FE4D8&gt; #converting iterator object to list object print(list(l1))#Output:['red', 'blue', 1, 2, 3, 'h', 'e', 'l', 'l', 'o']   l2=itertools.chain(\"ABC\",\"DEF\",\"GHI\") print (list(l2))#Output:['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']<\/code><\/pre>\n<\/p>\n<p>3<em>. <\/em><code>chain.from_iterable()<\/code><\/p>\n<p>\u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0435\u0440\u0435\u0442 \u043e\u0434\u0438\u043d \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u00ab\u0441\u043a\u043b\u0435\u0435\u043d\u043d\u044b\u0439\u00bb \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e. \u0412\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043f\u043e\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u043d\u0430 \u0432\u0445\u043e\u0434, \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u0438, \u0438\u043d\u0430\u0447\u0435 \u0432\u044b\u043f\u0430\u0434\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 TypeError.<\/p>\n<p><code>chain.from_iterable(iterable)<\/code><\/p>\n<pre><code class=\"python\">import itertools l1=itertools.chain.from_iterable([\"ABC\",\"DEF\",\"GHI\"]) print (list(l1))#Output:['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']  l2=itertools.chain([\"ABC\",\"DEF\",\"GHI\"]) print (list(l2))#Output:['ABC', 'DEF', 'GHI']  #all elements in the input iterable should be iterable.Otherwise it will raise TypeError. l3=itertools.chain.from_iterable([1,2,3]) print (list(l3))#Output:TypeError: 'int' object is not iterable<\/code><\/pre>\n<p>4<em>. <\/em><code>compress()<\/code><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b <em>data<\/em>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430\u0445 (<em>selectors<\/em>), \u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0432 True. \u041f\u0440\u0435\u043a\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u043b\u0438\u0431\u043e \u0434\u0430\u043d\u043d\u044b\u0435, \u043b\u0438\u0431\u043e \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438\u0441\u044c.&nbsp;<\/p>\n<p><code>itertools.compress(data,selectors)<\/code><\/p>\n<pre><code class=\"python\">import itertools selectors=[True,False,True,False] l1=itertools.compress([1,2,3,4],selectors) #Only returns element whose corresponding selector is True. print (list(l1))#Output:[1,3]   #filter - instead of passing an iterable of True and False. function is used to determine the value \"True or False\" l2=filter(lambda x:x%2!=0,[1,2,3,4]) print (list(l2))#Output:[1,3]<\/code><\/pre>\n<\/p>\n<p><em>5. <\/em><code>dropwhile()<\/code><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 (<em>predicate<\/em>) \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 True, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u0418\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u043d\u0435 \u0432\u0435\u0440\u043d\u0435\u0442 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u043a\u0430 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 False.<\/p>\n<p><code>itertools.dropwhile(predicate,iterable)<\/code><\/p>\n<\/p>\n<p>6<em>. <\/em><code>takewhile()<\/code><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 True.<\/p>\n<p><code>itertools.takewhile(predicate,iterable)<\/code><\/p>\n<pre><code class=\"python\">import itertools ##iterator will start displaying after condition is False. l1=itertools.dropwhile(lambda x:x&gt;4,[5,6,7,8,9,1,2,3]) print (l1)#Output:&lt;itertools.dropwhile object at 0x02E592C8&gt; print (list(l1))#Output:[1, 2, 3] #iterator used to print values till condition is False. l4=itertools.takewhile(lambda x:x&gt;4,[5,6,7,8,9,1,2,3]) print (list(l4))#Output:[5, 6, 7, 8, 9]   #iterator will start displaying after condition is False. l2=itertools.dropwhile(lambda x:x%2==0,[2,4,6,8,10]) print (list(l2))#Output:[] #iterator used to print values till condition is False. l3=itertools.takewhile(lambda x:x%2==0,[2,4,6,8,10]) print (list(l3))#Output:[2, 4, 6, 8, 10]<\/code><\/pre>\n<p>7<em>.<\/em><code>filterfalse()<\/code><em>:<\/em><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 False. \u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u0440\u0430\u0432\u0435\u043d None, \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u043e\u044f\u0442 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 False.&nbsp;<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>filter()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 True.<\/p>\n<pre><code>itertools.filterfalse(predicate,iterables)<\/code><\/pre>\n<pre><code class=\"python\">import itertools #iterator will filter the elements from the iterable which returns False for the given function l1=itertools.filterfalse(lambda x:x&gt;4,[1,2,3,4,5,6,7,8,9]) print (l1)#Output:&lt;itertools.filterfalse object at 0x0083E658&gt; print (list(l1))#Output:[1, 2, 3,4] #filter() function will  filter the elements from the iterable which returns True for the given function l4=filter(lambda x:x&gt;4,[1,2,3,4,5,6,7,8,9]) print (list(l4))#Output:[5, 6, 7, 8, 9]   #iterator will filter the elements from the iterable which returns False for the given function l2=itertools.filterfalse(lambda x:x%2==0,[2,4,6,8,10]) print (list(l2))#Output:[] #filter() function will filter the elements from the iterable which returns True for the given function l3=filter(lambda x:x%2==0,[2,4,6,8,10]) print (list(l3))#Output:[2, 4, 6, 8, 10]   #If predicate is None, returns the items that are False. l5=itertools.filterfalse(None,[0,1,2,3,4,5]) print (list(l5))#Output:[0] #If predicate is None,filter() function returns the items that are True. l6=filter(None,[0,1,2,3,4]) print (list(l6))#Output:[1, 2, 3, 4]<\/code><\/pre>\n<\/p>\n<p>8<em>. <\/em><code>zip_longest()<\/code><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0415\u0441\u043b\u0438 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438\u043c\u0435\u044e\u0442 \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443, \u0442\u043e \u043d\u0430 \u043c\u0435\u0441\u0442\u043e \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f <em>fillvalue<\/em>. \u0418\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f \u0441\u0430\u043c\u044b\u0439 \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<p>\u0412 <code>zip()<\/code> \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f \u0441\u0430\u043c\u044b\u0439 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<p><code>itertools.zip_longest(*iterables,fillvalue=None)<\/code><\/p>\n<pre><code class=\"python\">import itertools #fillvalue is not given,by default it will be None. #iteration continues until longest iterable is exhausted. z1=itertools.zip_longest([1,2,3,4,5],['a','b','c']) print (z1)#Output:&lt;itertools.zip_longest object at 0x00AA3BE0&gt; #we can iterate through zip object using for loop or we can convert to list object. print (list(z1))#Output:[(1, 'a'), (2, 'b'), (3, 'c'), (4, None), (5, None)]   #fillvalue is mentioned z2=itertools.zip_longest([1,2,3,4,5],['a','b','c'],fillvalue=\"z\") print (list(z2))#Output:[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'z'), (5, 'z')]   #using zip(),iteration continues until shorest iterable is exhausted. z3=zip([1,2,3,4,5],['a','b','c']) print (list(z3))#Output:[(1, 'a'), (2, 'b'), (3, 'c')]<\/code><\/pre>\n<\/p>\n<p>9<em>. <\/em><code>starmap()<\/code><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u043e\u043b\u0443\u0447\u0430\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u043e <em>map()<\/em>, \u043a\u043e\u0433\u0434\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0443\u0436\u0435 \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u043a\u043e\u0440\u0442\u0435\u0436\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435 (\u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u044b\u043b\u0438 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0436\u0430\u0442\u044b).<\/p>\n<p><code>itertools.starmap(function,iterable)<\/code><\/p>\n<pre><code class=\"python\">import itertools l1=itertools.starmap(pow,[(0,2),(1,2),(2,2)]) print (l1)#Output:&lt;itertools.starmap object at 0x00C8E4D8&gt; #We can iterate through starmap object,using for loop or using next() function. We can also convert to list object. print (list(l1))#Output:[0, 1, 4]   #using map() l2=map(pow,[0,1,2],[2,2,2]) print (list(l2))#Output:[0, 1, 4]   a1=map(lambda x:x**2,[1,2,3]) print (list(a1))#Output:[1, 4, 9]  #If elements inside the iterable are not iterable, it will raise TypeError. a2=itertools.starmap(lambda x:x**2,[1,2,3]) print (list(a2))#Output:TypeError: 'int' object is not iterable  a3=itertools.starmap(lambda x,y:x+y,[(0,1),(1,2),(2,3)]) print (list(a3))#Output:[1, 3, 5]<\/code><\/pre>\n<\/p>\n<p>10<em>. <\/em><code>islice()<\/code><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0415\u0441\u043b\u0438 <em>start<\/em> \u0440\u0430\u0432\u0435\u043d None, \u0442\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043d\u0443\u043b\u044f. \u0415\u0441\u043b\u0438 <em>step<\/em> \u0440\u0430\u0432\u0435\u043d None, \u0442\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0435\u043c\u0443 \u0434\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 1. \u0415\u0441\u043b\u0438 <em>stop<\/em> \u0440\u0430\u0432\u0435\u043d None, \u0442\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c\u0441\u044f, \u043f\u043e\u043a\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0430\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c\u0441\u044f. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438. \u0412 <code>islice()<\/code> \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 <em>start<\/em>, <em>stop<\/em> \u0438 <em>step<\/em>.<\/p>\n<p><code>itertools.islice(iterable,stop)<\/code><\/p>\n<p><code>itertools.islice(iterable, start, stop[, step])<\/code><\/p>\n<pre><code class=\"python\">import itertools #if only one argument is mentioned other than iterable,it is stop value. l1=itertools.islice([1,2,3,4,5,6,7,8,9,10],5) print (list(l1))#Output:[1, 2, 3, 4, 5]   #start=2 and stop=5 mentioned. It will start from second index and ends at fifth index l2=itertools.islice([1,2,3,4,5,6,7,8,9,10],2,5) print (list(l2))#Output:[3,4,5]   #start=2,step=3.It will start from second index and increment by 3. l3=itertools.islice([1,2,3,4,5,6,7,8,9,10],2,None,3) print (list(l3))#Output:[3,6,9]   #step is given as negative value,it raises ValueError l4=itertools.islice([1,2,3,4,5,6,7,8,9,10],2,None,-2) print (list(l4))#Output:ValueError: Step for islice() must be a positive integer or None.<\/code><\/pre>\n<\/p>\n<p>11<em>. <\/em><code>tee()<\/code><\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <em>n<\/em> \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p><code>itertools.tee(iterable,n=2)<\/code><\/p>\n<pre><code class=\"r\">import itertools l1=[1,2,3,4,5] l2=itertools.tee(l1,3) print (l2)#Output:(&lt;itertools._tee object at 0x028794C8&gt;, &lt;itertools._tee object at 0x028792C8&gt;, &lt;itertools._tee object at 0x02879528&gt;) for i in l2:     print (list(i)) ''' Output:     [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] '''<\/code><\/pre>\n<p>12<em>. <\/em><code>groupby()<\/code><em>:<\/em><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u043b\u044e\u0447\u0438 \u0438 \u0433\u0440\u0443\u043f\u043f\u044b \u0438\u0437 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p><em>key<\/em> \u2013 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0449\u0430\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0415\u0441\u043b\u0438 \u043a\u043b\u044e\u0447 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d \u0438\u043b\u0438 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 None, \u0442\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043a\u043b\u044e\u0447 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439.&nbsp;<\/p>\n<p><code>itertools.groupby(iterable,key=None)<\/code><\/p>\n<pre><code class=\"python\">import itertools l1=[('color','red'),('color','blue'),('color','green'),('Numbers',1),('Numbers',5)] l2=itertools.groupby(l1,key=lambda x:x[0]) print (l2)#Output:&lt;itertools.groupby object at 0x0305F528&gt; for key,group in l2:     result={key:list(group)}     print (result) ''' Output: {'color': [('color', 'red'), ('color', 'blue'), ('color', 'green')]} {'Numbers': [('Numbers', 1), ('Numbers', 5)]} '''  #list doesn't contain sorted data based on the key function.It breaks the group every time,when value of key function changes. l1=[('color','red'),('color','blue'),('color','green'),('Numbers',1),('Numbers',5),('color','purple')] l2=itertools.groupby(l1,key=lambda x:x[0]) print (l2)#Output:&lt;itertools.groupby object at 0x028AF5A0&gt;  for key,group in l2:     result={key:list(group)}     print (result) ''' Output: {'color': [('color', 'red'), ('color', 'blue'), ('color', 'green')]} {'Numbers': [('Numbers', 1), ('Numbers', 5)]} {'color': [('color', 'purple')]} '''   #key is not mentioned l1=[('color','red'),('color','blue'),('color','green'),('Numbers',1),('Numbers',5),('color','purple')] l2=itertools.groupby(l1) print (l2)#Output:&lt;itertools.groupby object at 0x028AF578&gt; for key,group in l2:     result={key:list(group)}     print (result) ''' Output: {('color', 'red'): [('color', 'red')]} {('color', 'blue'): [('color', 'blue')]} {('color', 'green'): [('color', 'green')]} {('Numbers', 1): [('Numbers', 1)]} {('Numbers', 5): [('Numbers', 5)]} {('color', 'purple'): [('color', 'purple')]}  '''<\/code><\/pre>\n<\/p>\n<p><strong>\u041a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u043d\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b:<\/strong><\/p>\n<p>1.<em> <\/em><code>product()<\/code><\/p>\n<p>\u0414\u0435\u043a\u0430\u0440\u0442\u043e\u0432\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043f\u043e\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u043d\u0430 \u0432\u0445\u043e\u0434.<\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u0435\u043a\u0430\u0440\u0442\u043e\u0432\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f: \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 <em>X<\/em> \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 <em>Y<\/em> \u2013 \u044d\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u0432\u0441\u0435 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u044b <em>(x, y)<\/em>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 <em>x<\/em> \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443 <em>X<\/em>, \u0430 <em>y<\/em> \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443 <em>Y<\/em>.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u043d\u0430 \u0441\u0435\u0431\u044f, \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0441 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c <em>repeat<\/em>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <em>product(A, repeat=4)<\/em> \u2013 \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 <em>product(A, A, A, A)<\/em>.<\/p>\n<p><code>itertools.product(*iterables,repeat)<\/code><\/p>\n<pre><code class=\"python\">import itertools #Only one iterable is given l1=itertools.product(\"ABCD\") print (list(l1))#Output:[('A',), ('B',), ('C',), ('D',)]   #two iterables are given l2=itertools.product(\"ABC\",[1,2]) print (list(l2))#Output:[('A', 1), ('A', 2), ('B', 1), ('B', 2), ('C', 1), ('C', 2)]   #one iterable and repeat is mentioned. l3=itertools.product(\"xy\",repeat=2) print (list(l3))#Output:[('x', 'x'), ('x', 'y'), ('y', 'x'), ('y', 'y')]   l4=itertools.product(\"aa\",repeat=2) print (list(l4))#Output:[('a', 'a'), ('a', 'a'), ('a', 'a'), ('a', 'a')]   #More than two iterables is mentioned l5=itertools.product([1,2],[3,4],[5,6]) print (list(l5))#Output:[(1, 3, 5), (1, 3, 6), (1, 4, 5), (1, 4, 6), (2, 3, 5), (2, 3, 6), (2, 4, 5), (2, 4, 6)]<\/code><\/pre>\n<p>2<em>. <\/em><code>permutations()<\/code><\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 <code>r<\/code> \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435. \u0415\u0441\u043b\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 r \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d \u0438\u043b\u0438 \u0441\u0442\u043e\u0438\u0442 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 None, \u0442\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e r \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u043b\u0438\u043d\u0443 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438. \u041a\u043e\u0440\u0442\u0435\u0436\u0438 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a \u0432\u044b\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u043b\u0435\u043a\u0441\u0438\u043a\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u043c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b, \u0442\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<p>\u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0438\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u0438, \u0430 \u043d\u0435 \u043e\u0442 \u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b, \u0442\u043e \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.&nbsp;<\/p>\n<p><code>itertools.permutations(iterable,r=None)<\/code><\/p>\n<pre><code class=\"python\">import itertools l1=itertools.permutations(\"ABC\") print (list(l1))#Output:[('A', 'B', 'C'), ('A', 'C', 'B'), ('B', 'A', 'C'), ('B', 'C', 'A'), ('C', 'A', 'B'), ('C', 'B', 'A')]   l2=itertools.permutations([3,2,1]) print (list(l2))#Output:[(3, 2, 1), (3, 1, 2), (2, 3, 1), (2, 1, 3), (1, 3, 2), (1, 2, 3)]   #elements are treated as unique based on their position and not by their value. l3=itertools.permutations([1,1]) print (list(l3))#Output:[(1, 1), (1, 1)]   l4=itertools.permutations([\"ABC\"]) print (list(l4))#Output:[('ABC',)]   #r value is mentioned as 2. It will return all different permutations in 2 values. l5=itertools.permutations([1,2,3,4],2) print (list(l5))#Output:[(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)]<\/code><\/pre>\n<p><strong><em>&nbsp;\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/em><\/strong><em> \u0432 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430\u0445 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/em><\/p>\n<p>3<em>. <\/em><code>combinations()<\/code><\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0434\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u0438\u043d\u044b <code>r<\/code> \u0438\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043f\u043e\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043d\u0430 \u0432\u0445\u043e\u0434.&nbsp;<\/p>\n<p>\u041a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043b\u0435\u043a\u0441\u0438\u043a\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d, \u0442\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<p>\u041b\u0435\u043a\u0441\u0438\u043a\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u2013 \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0432 \u0432 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.&nbsp;<\/p>\n<p>\u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0438\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u0438, \u0430 \u043d\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b, \u0442\u043e \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<p><code>itertools.combinations(iterable, r)<\/code><\/p>\n<\/p>\n<p>4<em>. <\/em><code>combination_swith_replacement()<\/code><em>:<\/em><\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0434\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u0438\u043d\u044b <code>r<\/code> \u0438\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043f\u043e\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043d\u0430 \u0432\u0445\u043e\u0434, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0430.&nbsp;<\/p>\n<p><code>itertools.combinations_with_replacement (iterable, r)<\/code><\/p>\n<pre><code class=\"python\">import itertools l1=itertools.combinations(\"ABC\",2) print (list(l1))#Output:[('A', 'B'), ('A', 'C'), ('B', 'C')] l1=itertools.combinations_with_replacement(\"ABC\",2) print (list(l1))#Output:[('A', 'A'), ('A', 'B'), ('A', 'C'), ('B', 'B'), ('B', 'C'), ('C', 'C')]   l2=itertools.combinations([3,2,1],3) print (list(l2))#Output:[(3, 2, 1)] l2=itertools.combinations_with_replacement([3,2,1],3) print(list(l2))#Output:[(3, 3, 3), (3, 3, 2), (3, 3, 1), (3, 2, 2), (3, 2, 1), (3, 1, 1), (2, 2, 2), (2, 2, 1), (2, 1, 1), (1, 1, 1)]   #elements are treated as unique based on their position and not by their value. l3=itertools.combinations([1,1],2) print (list(l3))#Output:[(1, 1)] l3=itertools.combinations_with_replacement([1,1],2) print (list(l3))#Output:[(1, 1), (1, 1), (1, 1)]   #since list contains only one element, given r value is 2. So it returns empty list. l4=itertools.combinations([\"ABC\"],2) print (list(l4))#Output:[] #In combinations_with_replacement,it allows repeated element. l4=itertools.combinations_with_replacement([\"ABC\"],2) print (list(l4))#Output:[('ABC', 'ABC')]   #r value is not mentioned. It will raise TypeError #l5=itertools.combinations([1,2,3,4]) #print (list(l5))#Output:TypeError: combinations() missing required argument 'r' (pos 2) l5=itertools.combinations_with_replacement([1,2,3,4]) print (list(l5))#Output:TypeError: combinations_with_replacement() missing required argument 'r' (pos 2)<\/code><\/pre>\n<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong><\/p>\n<p><strong>1. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 <\/strong><code>map()<\/code><strong> \u0438 <\/strong><code>zip()<\/code>:<\/p>\n<ul>\n<li>\n<p><code>count()&nbsp;<\/code><\/p>\n<\/li>\n<li>\n<p><code>repeat()<\/code><\/p>\n<\/li>\n<\/ul>\n<p><code>repeat()<\/code> &#8212; \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u043f\u043e\u0442\u043e\u043a\u0430 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>map()<\/code> \u0438\u043b\u0438 <code>zip()<\/code>.<\/p>\n<p><code>count() <\/code>&#8212; \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>map()<\/code> \u0438\u043b\u0438 <code>zip()<\/code>.<\/p>\n<\/p>\n<p><strong>2. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 <\/strong><code>cycle()<\/code><strong> \u0438 <\/strong><code>repeat()<\/code><strong>:<\/strong><\/p>\n<p><code>cycle()<\/code><em> \u2013<\/em> \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043d\u043e\u0432\u0430 \u0438 \u0441\u043d\u043e\u0432\u0430;<\/p>\n<p><code>repeat()<\/code><em> \u2013<\/em> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043d\u043e\u0432\u0430 \u0438 \u0441\u043d\u043e\u0432\u0430 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<\/p>\n<p><strong>3. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 <\/strong><code>reduce()<\/code><strong> \u0438 <\/strong><code>itertools.accumulate()<\/code>:<\/p>\n<p><code>reduce()<\/code><em>:<\/em><\/p>\n<ul>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u2013 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c.<\/p>\n<\/li>\n<\/ul>\n<p><code>accumulate()<\/code>:<\/p>\n<ul>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u043c \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0432\u043d\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u0432\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u2013 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439.<\/p>\n<\/li>\n<\/ul>\n<p><strong>4. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443<\/strong><code> filter()<\/code><strong> \u0438 <\/strong><code>itertools.compress()<\/code><strong>:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f<code> filter()<\/code><em> <\/em>\u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0441\u0442\u043e\u0438\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 True \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<\/li>\n<li>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>compress()<\/code> \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 True\/False.&nbsp;<\/p>\n<\/li>\n<\/ul>\n<p><strong>5. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443<\/strong><code> filter()<\/code><strong> \u0438 <\/strong><code>itertools.filterfalse()<\/code><strong>:<\/strong><\/p>\n<ul>\n<li>\n<p><code>filter()<\/code><em>: <\/em>\u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u0438\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0434\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 True.<\/p>\n<\/li>\n<li>\n<p><code>filterfalse()<\/code>: \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u0438\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0434\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 False.<\/p>\n<\/li>\n<\/ul>\n<p><strong>6. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 <\/strong><code>zip()<\/code><strong> \u0438 <\/strong><code>itertools.zip_longest()<\/code><strong><em>:<\/em><\/strong><\/p>\n<ul>\n<li>\n<p><code>zip()<\/code><em>: \u0418\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f \u0441\u0430\u043c\u044b\u0439 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442.<\/em><\/p>\n<\/li>\n<li>\n<p><code>zip_longest()<\/code>: \u0418\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f \u0441\u0430\u043c\u044b\u0439 \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<\/li>\n<\/ul>\n<p><strong>7. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0441\u0440\u0435\u0437\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0430 \u0438 <\/strong><code>itertools.islice()<\/code><strong><em>:<\/em><\/strong><\/p>\n<ul>\n<li>\n<p>\u0421\u0440\u0435\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a;<\/p>\n<\/li>\n<li>\n<p><code>islice()<\/code> \u2013 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0446\u0438\u043a\u043b \u0442\u0430\u043a, \u043a\u0430\u043a \u043d\u0430\u043c \u0443\u0434\u043e\u0431\u043d\u043e.&nbsp;<\/p>\n<\/li>\n<\/ul>\n<p><strong>8. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443<\/strong><code> itertools.permutations()<\/code><strong> \u0438 <\/strong><code>itertools.combinations()<\/code><strong>:<\/strong><\/p>\n<ul>\n<li>\n<p><code>itertools.permutations()<\/code><em>:<\/em> \u041f\u043e\u0440\u044f\u0434\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435;<\/p>\n<\/li>\n<li>\n<p><code>itertools.combinations()<\/code><em>:<\/em> \u041f\u043e\u0440\u044f\u0434\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.&nbsp;<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0438 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<\/p>\n<p>9. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 <code>itertools.combinations()<\/code> \u0438 <code>itertools.combination_swith_replacement<\/code><em>:<\/em><\/p>\n<ul>\n<li>\n<p><code>combinations()<\/code>: \u041f\u043e\u0440\u044f\u0434\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0442\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p><code>combination_swith_replacement()<\/code>: \u041f\u043e\u0440\u044f\u0434\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0442\u0441\u044f.<\/p>\n<\/li>\n<\/ul>\n<p><strong>10. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 <\/strong><code>itertools.takewhile()<\/code><strong> \u0438 <\/strong><code>itertools.dropwhile()<\/code><strong><em>:<\/em><\/strong><\/p>\n<ul>\n<li>\n<p><code>takewhile()<\/code><em>:<\/em> \u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043f\u043e\u043a\u0430 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 True.<\/p>\n<\/li>\n<li>\n<p><code>dropwhile()<\/code><em>:<\/em> \u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043f\u043e\u043a\u0430 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 True, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438:<\/strong><\/p>\n<p><em>Itertools<\/em>: <a href=\"https:\/\/docs.python.org\/3\/library\/itertools.html\">https:\/\/docs.python.org\/3\/library\/itertools.html<\/a><\/p>\n<hr>\n<blockquote>\n<p><a href=\"https:\/\/otus.pw\/Btqm\/\">\u0423\u0437\u043d\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043a\u0443\u0440\u0441\u0435.<\/a><\/p>\n<\/blockquote>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/529356\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/529356\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<blockquote>\n<p><strong>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 <\/strong><a href=\"https:\/\/otus.pw\/Btqm\/\"><strong>&#171;Python Developer. Basic&#187;<\/strong><\/a>.<\/p>\n<\/blockquote>\n<hr>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c <code>itertools<\/code> \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0431\u044b\u0441\u0442\u0440\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u0441\u0430\u043c\u0438 \u043f\u043e \u0441\u0435\u0431\u0435 \u0438\u043b\u0438 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438. \u0412\u043c\u0435\u0441\u0442\u0435 \u043e\u043d\u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442 \u00ab\u0430\u043b\u0433\u0435\u0431\u0440\u0443 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432\u00bb, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u043c Python.<\/p>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c itertools \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Python.<\/p>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0438\u043f\u044b \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432:&nbsp;<\/p>\n<ul>\n<li>\n<p>\u0411\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b;<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b;<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u043d\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043f\u043e \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e:<\/p>\n<ul>\n<li>\n<p>\u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>\u00abnext\u00bb<\/code><\/p>\n<\/li>\n<li>\n<p>\u0446\u0438\u043a\u043b\u0430 <code>for<\/code><\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>list()<\/code><\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0411\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b:<\/strong><\/p>\n<p><code>count()<\/code><em>, <\/em><code>cycle()<\/code><em>, <\/em><code>repeat()<\/code><\/p>\n<\/p>\n<p>1. <code>count()<\/code><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0447\u0438\u0441\u043b\u0430, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435 <em>start<\/em>. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <em>start<\/em> \u0440\u0430\u0432\u0435\u043d 0, \u0430 <em>step<\/em> -1. \u0428\u0430\u0433 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0446\u0435\u043b\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440.<\/p>\n<pre><code class=\"python\">import itertools c=itertools.count() #next() function returns next item in the iterator.By default starts with number 0 and increments by 1. print (next(c))#Output:0 print (next(c))#Output:1 print (next(c))#Output:2 print (next(c))#Output:3   #Returns an infinite iterator starting with number 5 and incremented by 10. The values in the iterator are accessed by next() c1=itertools.count(5,10) print(next(c1))#Output:5 print(next(c1))#Output:10 print(next(c1))#Output:15   #accessing values in the iterator using for loop.step argument can be float values also. c2=itertools.count(2.5,2.5) for i in c2:     #including terminating condition, else loop will keep on going.(infinite loop)     if i&gt;25:         break     else:         print (i,end=\" \") #Output:2.5 5.0 7.5 10.0 12.5 15.0 17.5 20.0 22.5 25.0           #step can be negative numbers also.negative numbers count backwards. c3=itertools.count(2,-2.5) print (next(c3))#Output:2 print (next(c3))#Output:-0.5 print (next(c3))#Output:-3.0<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 <code>map()<\/code> \u0438 <code>zip()<\/code>.<\/p>\n<p><code>zip()<\/code><em> <\/em>\u2013 \u044d\u0442\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f Python, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 <em>zip<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439. <code>itertools.count()<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>zip()<\/code>.<\/p>\n<pre><code class=\"python\">import itertools #itertools.count() used in zip() l1=[5,15,25] l2=zip(itertools.count(),l1) #It will return zip object which is an iterable instance of zip class print (l2)#Output:&lt;zip object at 0x032C92C8&gt;   #we can convert zip object to list. print (list(l2))#Output:[(0, 5), (1, 15), (2, 25)]   # We can access the zip object by using \"for loop\".This is more efficient way to access large sequences.It won't be memory intensive. l3=zip(itertools.count(),l1) for i in l3:     print (i) ''' Output: (0, 5) (1, 15) (2, 25) '''<\/code><\/pre>\n<\/p>\n<p><code>map()<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e \u0432\u0441\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u0432 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0435 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 <em>map<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>itertools.count()<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>map()<\/code>.<\/p>\n<pre><code class=\"python\">import itertools #lambda function and itertools.count() is given as argument in map()function. l1=map(lambda x:x**2,itertools.count()) #It returns a map object which is an iterator. print(l1)#Output:&lt;map object at 0x00E2E610&gt;  #iterate thorugh map object using for loop for i in l1:     if i&gt;50:         break     else:         print (i ,end=\" \")#Output:0 1 4 9 16 25 36 49<\/code><\/pre>\n<p>2.<em> <\/em><code>cycle()<\/code><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0449\u0438\u0439 \u043a\u043e\u043f\u0438\u044e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445. \u041a\u043e\u0433\u0434\u0430 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043f\u0438\u0438. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e.<\/p>\n<p><code>itertools.cycle(iterable)<\/code><\/p>\n<pre><code class=\"python\">import itertools l1=[1,2,3] #using list iterable as an argument in itertools.cycle() l2=itertools.cycle(l1) print (l2)#Output:&lt;itertools.cycle object at 0x02F794E8&gt;  count=0 for i in l2:     #It will end in infinite loop. So have to define terminating condition.     if count &gt; 15:         break     else:         print (i,end=\" \")#Output:1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1         count+=1           #string is given as an argument in itertools.cycle() function. s1=\"hello\" l3=itertools.cycle(s1) #accessing the iterator using next() print (next(l3))#Output:h print (next(l3))#Output:e print (next(l3))#Output:l print (next(l3))#Output:l print (next(l3))#Output:o<\/code><\/pre>\n<\/p>\n<p>3.<em> <\/em><code>repeat()<\/code>:<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043d\u043e\u0432\u0430 \u0438 \u0441\u043d\u043e\u0432\u0430. \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 <code>times<\/code>.<\/p>\n<p>\u041c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 <code>map()<\/code> \u0438 <code>zip()<\/code>.<\/p>\n<p><code>itertools.repeat(object,times)<\/code><\/p>\n<pre><code class=\"python\">import itertools #times argument is not mentioned. It will result in infinite loop. l1=itertools.repeat(2) print (next(l1))#Output:2 print (next(l1))#Output:2   #string is used as an argument.times argument is mentioned as 10.It will repeat the string 10 times. l2=itertools.repeat(\"hello\",times=10) for i in l2:     print (i,end=\" \")#Output:hello hello hello hello hello hello hello hello hello hello print (\" \")   #list is used as argument l3=itertools.repeat([1,2,3],times=3) for i in l3:     print (i,end=\" \")#Output:[1, 2, 3] [1, 2, 3] [1, 2, 3] print (\" \")   #tuple is used as an argument l4=itertools.repeat(('red','blue'),times=3) for i in l4:     print (i,end=\" \")#Output:('red', 'blue') ('red', 'blue') ('red', 'blue')<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>map()<\/code>.<\/p>\n<pre><code class=\"python\">import itertools #It will return square of numbers from 0 to 9. l1=map(pow,range(10),itertools.repeat(2)) print(l1)#Output:&lt;map object at 0x011CEC10&gt;  #iterate through map object using for loop for i in l1:     print (i,end=\" \") #Output:0 1 4 9 16 25 36 49 64 81<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>zip()<\/code>.<\/p>\n<pre><code class=\"python\">import itertools #itertools.repeat() used in zip() l1=[5,15,25] l2=zip(itertools.repeat(2),l1) #It will return zip object which is an iterable instance of zip class print (l2)#Output:&lt;zip object at 0x032794E8&gt;   #we can convert zip object to list. print (list(l2))#Output:[(2, 5), (2, 15), (2, 25)]   # We can access zip object by using for loop.This is more efficient way to access large sequences.It won't be memory intensive. l3=zip(itertools.repeat(\"hello\"),l1) for i in l3:     print (i) ''' Output: ('hello', 5) ('hello', 15) ('hello', 25) '''<\/code><\/pre>\n<p><strong>\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b:<\/strong><\/p>\n<\/p>\n<p>1<em>.<\/em><code>accumulate()<\/code><em>:<\/em><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u0443\u044e \u0441\u0443\u043c\u043c\u0443 \u0438\u043b\u0438 \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 <em>func<\/em>.&nbsp;<\/p>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <em>initial<\/em>, \u043e\u043d \u0442\u0430\u043a\u0436\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u0445\u043e\u0434\u043d\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0430 \u043e\u0434\u0438\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0432\u0445\u043e\u0434\u043d\u0430\u044f.&nbsp;<\/p>\n<p><code>functools.reduce()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.&nbsp;<\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440<code> initial<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0432 <em>Python \u0432\u0435\u0440\u0441\u0438\u0438 3.8.<\/em><\/p>\n<p><code>itertools.accumulate(iterable,func,*,initial=None)<\/code><\/p>\n<pre><code class=\"python\">import itertools #using add and mul operator,so importing operator module import operator #using reduce(),so importing reduce() from functools module from functools import reduce  #If func parameter is not mentioned,by default it will perform addition operation) l1=itertools.accumulate([1,2,3,4,5]) print (l1)#Output:&lt;itertools.accumulate object at 0x02CD94C8&gt; #Converting iterator to list object. print (list(l1))#Output:[1, 3, 6, 10, 15] #using reduce() for same function r1=reduce(operator.add,[1,2,3,4,5]) print (r1)#Output:15   #If initial parameter is mentioned, it will start accumulating from the initial value. #It will contain more than one element in the ouptut iterable. l2=itertools.accumulate([1,2,3,4,5],operator.add,initial=10) print (list(l2))#Output:[10, 11, 13, 16, 20, 25]   #it takes operator mul as function # It will perform multiplication on first two elements, then it will perform multiplication of next two element in the iterable. l3=itertools.accumulate([1,2,3,5,5],operator.mul) print (list(l3))#Output:[1, 2, 6, 30, 150] #using reduce() for same function mul. r2=reduce(operator.mul,[1,2,3,4,5]) print (r2)#Output:120   l4=itertools.accumulate([2,4,6,3,1],max) print (list(l4))#Output:[2, 4, 6, 6, 6] #using reduce for same function max r3=reduce(max,[2,4,6,3,1]) print (r3)#Output:6   #It takes min function as parameter. # It will compare two elements and find the minimum element,then compare the other elements and find the mininum element. l5=itertools.accumulate([2,4,6,3,1],min) print (list(l5))#Output:[2, 2, 2, 2, 1] #using reduce() for same function min r4=reduce(min,[2,4,6,3,1]) print (r4)#Output:1<\/code><\/pre>\n<\/p>\n<p>2.<em> <\/em><code>chain()<\/code><em>:<\/em><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043e\u043d \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0438\u0434\u0443\u0449\u0438\u0435 \u0434\u0440\u0443\u0433 \u0437\u0430 \u0434\u0440\u0443\u0433\u043e\u043c, \u043a\u0430\u043a \u043e\u0434\u043d\u0443.&nbsp;<\/p>\n<p><code>itertools.chain(*iterables)<\/code><\/p>\n<pre><code class=\"python\">import itertools l1=itertools.chain([\"red\",\"blue\"],[1,2,3],\"hello\") #Returns an iterator object print (l1)#Output:&lt;itertools.chain object at 0x029FE4D8&gt; #converting iterator object to list object print(list(l1))#Output:['red', 'blue', 1, 2, 3, 'h', 'e', 'l', 'l', 'o']   l2=itertools.chain(\"ABC\",\"DEF\",\"GHI\") print (list(l2))#Output:['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']<\/code><\/pre>\n<\/p>\n<p>3<em>. <\/em><code>chain.from_iterable()<\/code><\/p>\n<p>\u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0435\u0440\u0435\u0442 \u043e\u0434\u0438\u043d \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u00ab\u0441\u043a\u043b\u0435\u0435\u043d\u043d\u044b\u0439\u00bb \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e. \u0412\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043f\u043e\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u043d\u0430 \u0432\u0445\u043e\u0434, \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u0438, \u0438\u043d\u0430\u0447\u0435 \u0432\u044b\u043f\u0430\u0434\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 TypeError.<\/p>\n<p><code>chain.from_iterable(iterable)<\/code><\/p>\n<pre><code class=\"python\">import itertools l1=itertools.chain.from_iterable([\"ABC\",\"DEF\",\"GHI\"]) print (list(l1))#Output:['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']  l2=itertools.chain([\"ABC\",\"DEF\",\"GHI\"]) print (list(l2))#Output:['ABC', 'DEF', 'GHI']  #all elements in the input iterable should be iterable.Otherwise it will raise TypeError. l3=itertools.chain.from_iterable([1,2,3]) print (list(l3))#Output:TypeError: 'int' object is not iterable<\/code><\/pre>\n<p>4<em>. <\/em><code>compress()<\/code><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b <em>data<\/em>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430\u0445 (<em>se<\/em><\/p>\n<\/hr>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-313584","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=313584"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313584\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=313584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=313584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=313584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}