Successfully reported this slideshow.
Upcoming SlideShare
×

# EuroPython 2015 - Instructions

366 views

Published on

Instructions - working with Python iterable data structures made easy.

Published in: Software
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Like to know how to take easy surveys and get huge checks - then you need to visit us now! Having so many paid surveys available to you all the time let you live the kind of life you want. learn more...▲▲▲ http://ishbv.com/surveys6/pdf

Are you sure you want to  Yes  No
• Like to know how to take easy surveys and get huge checks - then you need to visit us now! Having so many paid surveys available to you all the time let you live the kind of life you want. learn more...★★★ https://tinyurl.com/realmoneystreams2019

Are you sure you want to  Yes  No
• Be the first to like this

### EuroPython 2015 - Instructions

1. 1. 1 / 17 Instructions Max Tepkeev 20 July 2015 Bilbao, Spain
2. 2. 2 / 17
3. 3. 3 / 17
4. 4. 4 / 17
5. 5. 5 / 17 Task Find all strings with a length of 3 >>> container = ['foo', 'bar', 'yada' 1, 2] >>> results = [] >>> for item in container: ... if isinstance(item, str) and len(item) == 3: ... results.append(item) >>> print results ['foo', 'bar']
6. 6. 6 / 17 Task Find all strings with a length of 3 >>> container = ['foo', 'bar', 'yada' 1, 2] >>> results = [item for item in container if isinstance(item, str) and len(item) == 3] >>> print results ['foo', 'bar']
7. 7. 7 / 17 Task Find all strings with a length of 3 >>> container = ['foo', 'bar', 'yada', ['olo', 3, [4, 'baz']], 1, 2] >>> def finder(searchable): ... results = [] ... for item in searchable: ... if isinstance(item, str) and len(item) == 3: ... results.append(item) ... elif isinstance(item, list): ... results.extend(finder(item)) ... return results >>> print finder(container) ['foo', 'bar', 'olo', 'baz']
8. 8. 8 / 17 Task Find all strings with a length of 3 >>> container = ['foo', 'bar', 'yada' 1, 2] >>> import instructions as i >>> results = i.findstring__len(3).inside(container) >>> print list(results) ['foo', 'bar']
9. 9. 9 / 17 Task Find all strings with a length of 3 >>> container = ['foo', 'bar', 'yada', ['olo', 3, [4, 'baz']], 1, 2] >>> import instructions as i >>> results = i.findstring__len(3).inside(container) >>> print list(results) ['foo', 'bar', 'olo', 'baz']
10. 10. 10 / Task Find all strings with a length of 3 >>> container = ['foo', 'bar', 'yada', ['olo', 3, [4, 'baz']], 1, 2] >>> import instructions as i >>> options = dict(level=1, limit=1, ignore=[tuple]) >>> results = i.findstring__len(3, **options).inside(container) >>> print list(results) ['foo']
11. 11. 11 / Concepts • find – command • string – datatype • len – filter • 3 – filter argument • level, ignore - options findstring__len(3, level=1, ignore=[tuple])
12. 12. 12 / Examples • findstring__lengte(3) • findnumeric__between(5, 10) • countint__divisibleby(2) • firstlist__contains_all(['foo', 'baz']) • lasttuple__str_contains_str('ba') • existsset__issuperset(set(['bar'])) • finddict__contains_all_keys(['a', 'b']) • finddict__key_contains_str('ab') • finddict__contains_any_values(['b', 'ba'])
13. 13. 13 / Advanced Mode >>> container = ['foobar', 'fooyadabar', 2] >>> from instructions import commands, datatypes >>> result = commands.count( ... datatypes.string.startswith('foo') & ... datatypes.string.endswith('bar') & ... ~datatypes.string.contains('yada') ... ).inside(container) >>> print result 1
14. 14. 14 / Installation From PyPi: \$ pip install instructions or clone from github: \$ git clone git://github.com/maxtepkeev/instructions.git
15. 15. 15 / Features • Python 2.6 - 3.4, PyPy, PyPy3 • No external dependencies • Documentation at Read the Docs • More than 100 instructions included • 100% test coverage • Library – 400 LOC • Tests – 3600 LOC
16. 16. 16 / Supported Python Datatypes bool long str complex unicode list bytes tuple bytearray set int frozenset float dict numeric iterable
17. 17. 17 / Contacts https://github.com/maxtepkeev/instructions slides: http://slideshare.net/maxtepkeev email: tepkeev@gmail.com skype: max.tepkeev