Python 3: A Step-by-Step Guide to Learn, in an Easy Way, the Fundamentals of Python Programming Language by John Bach
Author:John Bach [Bach, John]
Language: eng
Format: azw3, epub, azw, pdf
Published: 2020-09-17T16:00:00+00:00
Regex substitutions are extremely powerful, and the \ 1 syntax makes them even more powerful. But the whole operation, combined into one regular expression, also becomes difficult to read, in addition, this method does not directly correlate with how you originally described the rules for forming the plural. Initially, you designed rules in the form "if a word ends in S , X, or Z , add ES ." And if you are looking at a function, then you have two lines of code that say "if the word ends in S , X, or Z , add ES ." It will not work even closer to the original version.
Feature List
Now you will add an abstraction layer. You started by defining a list of rules: if this is true, do that, otherwise refer to the next rule. Let's temporarily complicate part of the program so that you can simplify another part of it.
import re def match_sxz ( noun ) : return re . search ( '[sxz] $' , noun ) def apply_sxz ( noun ) : return re . sub ( '$' , 'es' , noun ) def match_h ( noun ) : return re . search ( '[^ aeioudgkprt] h $' , noun ) def apply_h ( noun ) : return re . sub ( '$' , 'es' , noun ) def match_y ( noun ) : ① return re . search ( '[^ aeiou] y $' , noun ) def apply_y ( noun ) : ② return re . sub ( 'y $' , 'ies' , noun ) def match_default ( noun ) : return True def apply_default ( noun ) : return noun + 's' rules = (( match_sxz , apply_sxz ) , ③ ( match_h , apply_h ) , ( match_y , apply_y ) , ( match_default , apply_default ) ) def plural ( noun ) : for matches_rule , apply_rule in rules: ④ if matches_rule ( noun ) : return apply_rule ( noun )
Download
Python 3: A Step-by-Step Guide to Learn, in an Easy Way, the Fundamentals of Python Programming Language by John Bach.epub
Python 3: A Step-by-Step Guide to Learn, in an Easy Way, the Fundamentals of Python Programming Language by John Bach.azw
Python 3: A Step-by-Step Guide to Learn, in an Easy Way, the Fundamentals of Python Programming Language by John Bach.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9875)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9763)
The Mikado Method by Ola Ellnestam Daniel Brolund(9754)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8264)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7756)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7748)
Grails in Action by Glen Smith Peter Ledbrook(7673)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7524)
Windows APT Warfare by Sheng-Hao Ma(6532)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6385)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6280)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6155)
Kotlin in Action by Dmitry Jemerov(5025)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4304)
Functional Programming in JavaScript by Mantyla Dan(4025)
Solidity Programming Essentials by Ritesh Modi(3861)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3634)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3583)
The Ultimate iOS Interview Playbook by Avi Tsadok(3554)
