[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
More functions are not introduced here. You can view the pipe source files. For a total of less than 600 lines of files, 300 of them are documents, which contain a large number of examples.
Pipe is very simple to implement. It uses the Pipe decorator to aggregate common generator functions (or return the functions of the iterator) the proxy can be used on a common class instance that implements the _ ror _ method, but this idea is really interesting.
One interview question:
Read the file, count the number of times each word appears in the file, and sort by the number of times.
This is a simple question, but it is interesting to combine it with the Pipe just introduced. This type of data stream processing is quite suitable for processing with Pipe. It took some time, write the following code:
#coding=utf-8from re import splitfrom pipe import *with open(r'C:UsersAdministratorDesktop.py') as f: print(f.read() | Pipe(lambda x:split('W+', x)) | Pipe(lambda x:(i for i in x if i.strip())) | groupby(lambda x:x) | select(lambda x:(x[0], (x[1] | count))) | sort(key=lambda x:x[1], reverse=True) )
Output result:
[('Request', 91), ('post', 81), ('and', 38), ('U', 36), ('if ', 33), ('in', 32), ('team', 29), ('line', 23), ('objects', 20), ('gcmgroup ', 16), ('get', 14), ('import', 14), ('save', 13), ('str', 12), ('0 ', 11), ('1', 11), ('I', 11), ('false', 10), ('gcwgroups ', 9), ('from ', 9), ('group _ name', 9), ('path', 9), ('Team _ groupup', 9), ('add', 8 ), ('else', 8), ('extra _ context', 8), ('form2', 8), ('Return ', 8), ('region ', 7), ('baoming', 7), ('cname', 7), ('cname1', 7), ('cname2', 7), ('form1 ', 7), ('mysql _ cur', 7), ('8', 6), ('gender', 6), ('is _ del ', 6 ), ('time', 6), ('user', 6), ('20', 5), ('7', 5), ('def ', 5 ), ('depth ', 5), ('for', 5), ('gcwteam', 5), ('radio1', 5), ('13', 4 ), ('16', 4), ('2', 4), ('000000', 4), ('5', 4), ('gb2312', 4 ), ('gcwmember', 4), ('gcwmemberform', 4), ('gcwteam', 4), ('gcwteamform', 4), ('httpresponseredirect', 4 ), ('age', 4), ('append', 4), ('area1', 4), ('cad _ id', 4), ('csv ', 4), ('django ', 4), ('email', 4), ('encoding', 4), ('fax', 4 ), ('gr _ name', 4), ('lines', 4), ('name', 4), ('ob', 4), ('phone ', 4), ('qq', 4), ('response', 4), ('status', 4), ('Team _ user', 4 ), ('template _ name', 4), ('123', 3), ('12', 3), ('4', 3), ('requestcontext ', 3), ('true', 3), ('A', 3), ('areas', 3), ('cname3', 3), ('communi ', 3), ('create', 3), ('csa ', 3), ('diyi', 3), ('filter', 3), ('gcmmember ', 3), ('gcw ', 3), ('hd _ cont', 3), ('id', 3), ('LIST', 3 ), ('mysql _ db', 3), ('pp ', 3), ('radio2', 3), ('radio3', 3), ('radio4 ', 3), ('radio9', 3), ('Render _ to_response', 3), ('result', 3), ('shiyun ', 3 ), ('sys ', 3), ('t _ id', 3), ('textfield10', 3), ('textfield11', 3), ('textfield12 ', 3), ('textfield13', 3), ('textfield14', 3), ('textfield15', 3), ('textfield16', 3), ('textfield5 ', 3), ('textfield6 ', 3), ('textfield7', 3), ('textfield8', 3), ('textfield9', 3), ('title ', 3), ('topic ', 3), ('writers', 3), ('3', 2), ('50', 2), ('from ', 2), ('http404', 2), ('httpresponse', 2), ('mysqldb', 2), ('select', 2), ('where ', 2), ('all', 2), ('area2 ', 2), ('area3', 2), ('baoming _ user', 2 ), ('close', 2), ('commit ', 2), ('Context _ instance', 2), ('cut _ page', 2 ), ('diqu', 2), ('execute t', 2), ('execute ', 2), ('ftp', 2), ('ftp _ status ', 2), ('gcw _ baoming_list ', 2), ('gcw _ team', 2), ('get _ full_area', 2), ('group _ community ', 2), ('group _ farmer ', 2), ('group _ org', 2), ('group _ other ', 2), ('group _ pupils ', 2), ('group _ students', 2), ('group _ tertiary ', 2), ('group _ troops', 2), ('is _ valid ', 2), ('len', 2), ('login _ required', 2), ('models', 2), ('not', 2 ), ('page', 2), ('pk', 2), ('recommend _ type', 2), ('result', 2), ('root ', 2), ('select _ SQL ', 2), ('select _ SQL _mem', 2), ('set _ gcw_ftpd ', 2), ('st2 ', 2), ('todo ', 2), ('try', 2), ('url', 2), ('username', 2), ('utf ', 2), ('10', 1), ('11', 1), ('000000', 1), ('17', 1), ('18 ', 1), ('20140901', 1), ('20160901', 1), ('9', 1), ('content', 1), ('disposition ', 1), ('E', 1), ('qq', 1), ('raysize', 1), ('attachment ', 1), ('auth ', 1), ('baoshaowei', 1), ('Break', 1), ('charset', 1), ('cleaned _ data', 1 ), ('coding', 1), ('connect', 1), ('trigger', 1), ('cursor ', 1), ('D', 1 ), ('datetime', 1), ('db', 1), ('recorator', 1), ('en', 1), ('excel ', 1 ), ('extend', 1), ('fetchall', 1), ('fetchall', 1), ('filename', 1), ('forms ', 1 ), ('ftpd ', 1), ('gcw130', 1), ('gcw _ baoming ', 1), ('gcw _ baoming_csv', 1 ), ('gcw _ shipin_status ', 1), ('gcwteam _ set', 1), ('get _ object_or_404', 1), ('hbl', 1 ), ('hbl _ cassi', 1), ('host', 1), ('html', 1), ('http', 1), ('insert ', 1), ('int', 1), ('is _ captain ', 1), ('m _ author', 1), ('m _ name ', 1), ('mail', 1), ('method', 1), ('metype ', 1), ('order _ by', 1 ), ('pages ', 1), ('passwd', 1), ('print', 1), ('raise ', 1), ('range', 1 ), ('Re', 1), ('recommend _ name', 1), ('reload', 1), ('setdefaultencoding ', 1), ('shortcuts ', 1), ('Team _ age', 1), ('Team _ region', 1), ('Team _ area_id ', 1), ('Team _ man_num ', 1), ('Team _ name', 1), ('Team _ num', 1), ('Team _ woman_num ', 1), ('template ', 1), ('text', 1), ('textfield21', 1), ('textfield22', 1), ('textfield23', 1), ('textfield24 ', 1), ('textfield25', 1), ('textfield26', 1), ('textfield61 ', 1), ('textfield71', 1), ('textfield81 ', 1), ('topic _ gcwmember ', 1), ('topic _ gcwteam', 1), ('userdb', 1), ('users', 1 ), ('utf8', 1), ('util', 1), ('views', 1), ('while ', 1), ('wohnort3', 1 ), ('Works _ long', 1), ('Works _ name', 1), ('Works _ type', 1), ('writer', 1 ), ('writerow', 1), ('writeraws', 1)]