SlideShare a Scribd company logo
Super Advanced Python –act1 
https://www.spkrbar.com/talk/11 
參考Raymond Chandler III演講
Built-in Functions 
abs() divmod() input() open() staticmethod() 
all() enumerate() int() ord() str() 
any() eval() isinstance() pow() sum() 
basestring() execfile() issubclass() print() super() 
bin() file() iter() property() tuple() 
bool() filter() len() range() type() 
bytearray() float() list() raw_input() unichr() 
callable() format() locals() reduce() unicode() 
chr() frozenset() long() reload() vars() 
classmethod() getattr() map() repr() xrange() 
cmp() globals() max() reversed() zip() 
compile() hasattr() 
memoryvie 
w() 
round() __import__() 
complex() hash() min() set() apply() 
delattr() help() next() setattr() buffer() 
dict() hex() object() slice() coerce() 
dir() id() oct() sorted() intern()
Built-in Functions 
• 內建型態(Built-in type) 
– 數值型態(Numeric type) 
- int, long, float, bool, complex 
– 字串型態(String type) 
• 補充format 
>>> '%(real)s is %(nick)s' % {'real' : 'Justin', 'nick' : 'caterpillar'} 
'Justin is caterpillar‘ 
>>> '{0} is {1}'.format('Justin', 'caterpillar') 
'Justin is caterpillar' 
– 容器型態(Container type) 
- list, set, dict, tuple
三種基本type 
• list 型態 
• set 型態 
• dict 型態 
• tuple 型態
List comprehension 
• list = [1,2,3,4,5] 
{1: 10, 2: 20, 3: 30, 4: 40, 5: 50} 
{1: 10, 2: 20, 3: 30, 4: 40, 5: 50} 
[(1, 10), (2, 20), (3, 30), (4, 40), (5, 50)] 
[(1, 100), (2, 200), (3, 300), (4, 400), (5, 500)] 
{1: 11, 2: 21, 3: 31, 4: 41, 5: 51} 
{'a': 2, 'c': 6, 'b': 4} 
print(dict([(v,v*10)for v in list])) 
print({v:v*10 for v in list}) 
my_dict = {v:v*10 for v in list} 
print(my_dict.items()) 
result = [(k,v*10) for (k,v) in my_dict.items()] 
print(result) 
dict_compr = {k:v+1 for k,v in my_dict.items()} 
print(dict_compr) 
# correct method 
my_dicts = {'a':1 ,'b':2, 'c':3} 
print({k:v*2 for k, v in my_dicts.items()}) 
Items(): 
#return (key, value) pairs 
還有iterkeys(), itervalues(), iteritems()
Dict comprehension 
• my_dicts = {'a':1 ,'b':2, 'c':3} 
result = {k:v*2 for k, v in my_dicts.items()} 
print(result) 
print(result.iterkeys()) 
print(result.itervalues()) 
print(result.iteritems()) 
pairs1 = zip(result.iterkeys(),result.itervalues()) 
print(pairs1,type(pairs1)) 
pairs2 = [(v,k) for (k,v) in result.iteritems()] 
print(pairs2,type(pairs2)) 
{'a': 2, 'c': 6, 'b': 4} 
<dictionary-keyiterator object at 0x7f3bd764c940> 
<dictionary-valueiterator object at 0x7f3bd764c940> 
<dictionary-itemiterator object at 0x7f3bd764c940> 
([('a', 2), ('c', 6), ('b', 4)], <type 'list'>) 
([(2, 'a'), (6, 'c'), (4, 'b')], <type 'list'>)
Lambda 
• my_list = [1,2,3,4,5] 
def my_func(item): 
return item *2 
print([my_func(x) for x in my_list]) 
other_func = lambda x: x*2 
print([other_func(x) for x in my_list]) 
print(map(lambda i:i*2,my_list)) 
print(map(lambda i:i*i,my_list)) 
[2, 4, 6, 8, 10] 
[2, 4, 6, 8, 10] 
[2, 4, 6, 8, 10] 
[1, 4, 9, 16, 25]
Enumerate 
• my_first_list = ['a', 'b', 'c', 'd', 'e'] 
my_second_list = [1,2,3,4,5] 
print(zip(my_first_list, my_second_list)) 
print(enumerate(my_first_list)) 
print(enumerate(my_first_list, 3)) 
for i,j in enumerate(my_first_list,1): 
print(i,j) 
print([(i,j) for i,j in enumerate(my_first_list,1)]) 
[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)] 
<enumerate object at 0x7f3bd764d870> 
<enumerate object at 0x7f3bd764d870> 
(1, 'a') 
(2, 'b') 
(3, 'c') 
(4, 'd') 
(5, 'e') 
[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')]
zip 
• my_first_list = "abcde" 
my_second_list = "zyxwv" 
result = zip(my_first_list, my_second_list) 
print(result) 
result2 = [''.join(x) for x in result] 
print(result2) 
result3 = ['123'.join(x) for x in result] 
print(result3) 
print(dict(result)) 
print([(k*3,v) for k,v in result]) 
[('a', 'z'), ('b', 'y'), ('c', 'x'), ('d', 'w'), ('e', 'v')] 
['az', 'by', 'cx', 'dw', 'ev'] 
['a123z', 'b123y', 'c123x', 'd123w', 'e123v'] 
{'a': 'z', 'c': 'x', 'b': 'y', 'e': 'v', 'd': 'w'} 
[('aaa', 'z'), ('bbb', 'y'), ('ccc', 'x'), ('ddd', 'w'), ('eee', 'v')]
filter 
• my_list = [1,2,3,4,5,6] 
print([x for x in my_list if x % 2 == 0]) 
print(filter(lambda x: x % 2 == 0, my_list)) 
#filter(function, iterable) 
[2, 4, 6] 
[2, 4, 6]
Any / all 
• my_list = [True,False,False,False] 
print(any(my_list)) 
print(all(my_list)) 
my_list2 = [True,True,True] 
print(any(my_list2)) 
print(all(my_list2)) 
True 
False 
True 
True
• all(iterable)Return True if all elements of the iterable are true (or if the 
iterable is empty). Equivalent to: 
• def all(iterable): 
for element in iterable: 
if not element: 
return False 
return True 
• any(iterable)Return True if any element of the iterable is true. If the iterable 
is empty, return False. Equivalent to: 
• def any(iterable): 
for element in iterable: 
if element: return True 
return False
map 
• my_list = range(1,7) 
#range(start, stop[, step]) 
print(my_list) 
print([x *2 for x in my_list]) 
range(): 
#range(start, stop[, step]) 
print(map(lambda x:x *2 , my_list)) 
[1, 2, 3, 4, 5, 6] 
[2, 4, 6, 8, 10, 12] 
[2, 4, 6, 8, 10, 12]
reduce 
• val = 0 
for x in range(1,7): 
val += x 
print(val) 
print(reduce(lambda x,y: x+y, range(1,7))) 
print(reduce(lambda x,y: x*y, range(1,7))) 
print(sum(range(1,7))) 
21 
21 
720 
21
參考網頁 
• http://www.codedata.com.tw/python/python-tutorial-the-2nd-class- 
2-container-flow-for-comprehension/ 
• http://54im.com/python/%E3%80%90python-2-73-1- 
%E6%96%B0%E7%89%B9%E6%80%A7%E3%80%91%E5%AD%97%E 
5%85%B8%E6%8E%A8%E5%AF%BC%E5%BC%8F%EF%BC%88dictio 
nary-comprehensions%EF%BC%89.html 
• https://docs.python.org/2/library/stdtypes.html?highlight=dict#dict 
.items 
• http://pydoing.blogspot.tw/2011/02/python-enumerate.html 
• http://pydoing.blogspot.tw/2011/03/python-strjoin.html 
• http://pydoing.blogspot.tw/2011/02/python-filter.html 
• https://docs.python.org/2/library/functions.html#all 
• https://docs.python.org/2/library/functions.html#reduce 
• https://www.spkrbar.com/talk/11

More Related Content

What's hot

Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Tsuyoshi Yamamoto
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeMongoDB
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Pythonpugpe
 
MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤Takahiro Inoue
 
MongoDB全機能解説2
MongoDB全機能解説2MongoDB全機能解説2
MongoDB全機能解説2Takahiro Inoue
 
Javascript
JavascriptJavascript
Javascript
Vlad Ifrim
 
Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
Lorenz Cuno Klopfenstein
 
mobl - model-driven engineering lecture
mobl - model-driven engineering lecturemobl - model-driven engineering lecture
mobl - model-driven engineering lecturezefhemel
 
python高级内存管理
python高级内存管理python高级内存管理
python高级内存管理
rfyiamcool
 
大量地区化解决方案V5
大量地区化解决方案V5大量地区化解决方案V5
大量地区化解决方案V5
bqconf
 
JavaScript Code Formatting With Prettier by Christopher Chedeau
JavaScript Code Formatting With Prettier by Christopher ChedeauJavaScript Code Formatting With Prettier by Christopher Chedeau
JavaScript Code Formatting With Prettier by Christopher Chedeau
React London 2017
 
Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018
Timur Shemsedinov
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyBrian Aker
 
Litebox
LiteboxLitebox
Litebox
meli media
 
Advanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part IIAdvanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part II
Dr. Volkan OBAN
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter Bootstrap
Howard Lewis Ship
 
How fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceHow fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practice
Tobias Pfeiffer
 
Gearman, from the worker's perspective
Gearman, from the worker's perspectiveGearman, from the worker's perspective
Gearman, from the worker's perspective
Brian Aker
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
niklal
 

What's hot (20)

Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Python
 
MongoDB Oplog入門
MongoDB Oplog入門MongoDB Oplog入門
MongoDB Oplog入門
 
MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤MongoDBで作るソーシャルデータ新解析基盤
MongoDBで作るソーシャルデータ新解析基盤
 
MongoDB全機能解説2
MongoDB全機能解説2MongoDB全機能解説2
MongoDB全機能解説2
 
Javascript
JavascriptJavascript
Javascript
 
Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
 
mobl - model-driven engineering lecture
mobl - model-driven engineering lecturemobl - model-driven engineering lecture
mobl - model-driven engineering lecture
 
python高级内存管理
python高级内存管理python高级内存管理
python高级内存管理
 
大量地区化解决方案V5
大量地区化解决方案V5大量地区化解决方案V5
大量地区化解决方案V5
 
JavaScript Code Formatting With Prettier by Christopher Chedeau
JavaScript Code Formatting With Prettier by Christopher ChedeauJavaScript Code Formatting With Prettier by Christopher Chedeau
JavaScript Code Formatting With Prettier by Christopher Chedeau
 
Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
 
Litebox
LiteboxLitebox
Litebox
 
Advanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part IIAdvanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part II
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter Bootstrap
 
How fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceHow fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practice
 
Gearman, from the worker's perspective
Gearman, from the worker's perspectiveGearman, from the worker's perspective
Gearman, from the worker's perspective
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 

Viewers also liked

PythonBrasil[8] closing
PythonBrasil[8] closingPythonBrasil[8] closing
PythonBrasil[8] closing
Tatiana Al-Chueyr
 
Vim for Mere Mortals
Vim for Mere MortalsVim for Mere Mortals
Vim for Mere Mortals
Clayton Parker
 
The Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribThe Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contrib
Tzu-ping Chung
 
User-centered open source
User-centered open sourceUser-centered open source
User-centered open source
Jacqueline Kazil
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework  for perfectionists with deadlinesDjango - The Web framework  for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
Markus Zapke-Gründemann
 
NoSql Day - Apertura
NoSql Day - AperturaNoSql Day - Apertura
NoSql Day - Apertura
WEBdeBS
 
2 × 3 = 6
2 × 3 = 62 × 3 = 6
2 × 3 = 6
Tzu-ping Chung
 
Django-Queryset
Django-QuerysetDjango-Queryset
Django-Queryset
Mindfire Solutions
 
Website optimization
Website optimizationWebsite optimization
Website optimization
Mindfire Solutions
 
Rabbitmq & Postgresql
Rabbitmq & PostgresqlRabbitmq & Postgresql
Rabbitmq & Postgresql
Lucio Grenzi
 
2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python
Jiho Lee
 
PyClab.__init__(self)
PyClab.__init__(self)PyClab.__init__(self)
PyClab.__init__(self)
Tzu-ping Chung
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - Chiusura
WEBdeBS
 
Digesting jQuery
Digesting jQueryDigesting jQuery
Digesting jQuery
Mindfire Solutions
 
라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘
Jiho Lee
 
Overview of Testing Talks at Pycon
Overview of Testing Talks at PyconOverview of Testing Talks at Pycon
Overview of Testing Talks at Pycon
Jacqueline Kazil
 
Html5 History-API
Html5 History-APIHtml5 History-API
Html5 History-API
Mindfire Solutions
 
Bottle - Python Web Microframework
Bottle - Python Web MicroframeworkBottle - Python Web Microframework
Bottle - Python Web Microframework
Markus Zapke-Gründemann
 
Load testing
Load testingLoad testing
Load testing
Mindfire Solutions
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia ContiniWEBdeBS
 

Viewers also liked (20)

PythonBrasil[8] closing
PythonBrasil[8] closingPythonBrasil[8] closing
PythonBrasil[8] closing
 
Vim for Mere Mortals
Vim for Mere MortalsVim for Mere Mortals
Vim for Mere Mortals
 
The Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribThe Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contrib
 
User-centered open source
User-centered open sourceUser-centered open source
User-centered open source
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework  for perfectionists with deadlinesDjango - The Web framework  for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
 
NoSql Day - Apertura
NoSql Day - AperturaNoSql Day - Apertura
NoSql Day - Apertura
 
2 × 3 = 6
2 × 3 = 62 × 3 = 6
2 × 3 = 6
 
Django-Queryset
Django-QuerysetDjango-Queryset
Django-Queryset
 
Website optimization
Website optimizationWebsite optimization
Website optimization
 
Rabbitmq & Postgresql
Rabbitmq & PostgresqlRabbitmq & Postgresql
Rabbitmq & Postgresql
 
2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python2016 py con2016_lightingtalk_php to python
2016 py con2016_lightingtalk_php to python
 
PyClab.__init__(self)
PyClab.__init__(self)PyClab.__init__(self)
PyClab.__init__(self)
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - Chiusura
 
Digesting jQuery
Digesting jQueryDigesting jQuery
Digesting jQuery
 
라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘라이트닝 토크 2015 파이콘
라이트닝 토크 2015 파이콘
 
Overview of Testing Talks at Pycon
Overview of Testing Talks at PyconOverview of Testing Talks at Pycon
Overview of Testing Talks at Pycon
 
Html5 History-API
Html5 History-APIHtml5 History-API
Html5 History-API
 
Bottle - Python Web Microframework
Bottle - Python Web MicroframeworkBottle - Python Web Microframework
Bottle - Python Web Microframework
 
Load testing
Load testingLoad testing
Load testing
 
Django e il Rap Elia Contini
Django e il Rap Elia ContiniDjango e il Rap Elia Contini
Django e il Rap Elia Contini
 

Similar to Super Advanced Python –act1

Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturial
Wayne Tsai
 
Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수
용 최
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
decoupled
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
Aleksandar Veselinovic
 
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
CloudxLab
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python Tricks
Bryan Helmig
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
gekiaruj
 
Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
Brian Lonsdorf
 
Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기
JangHyuk You
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
Paige Bailey
 
R programming language
R programming languageR programming language
R programming language
Alberto Minetti
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
Svet Ivantchev
 
Python basic
Python basic Python basic
Python basic
sewoo lee
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Frsa
FrsaFrsa
Frsa
_111
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavVyacheslav Arbuzov
 
Groovy collection api
Groovy collection apiGroovy collection api
Groovy collection api
trygvea
 
Scala Functional Patterns
Scala Functional PatternsScala Functional Patterns
Scala Functional Patterns
league
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::Util
Nova Patch
 

Similar to Super Advanced Python –act1 (20)

Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturial
 
Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python Tricks
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
 
Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
 
R programming language
R programming languageR programming language
R programming language
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
Python basic
Python basic Python basic
Python basic
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Frsa
FrsaFrsa
Frsa
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
 
Groovy collection api
Groovy collection apiGroovy collection api
Groovy collection api
 
Scala Functional Patterns
Scala Functional PatternsScala Functional Patterns
Scala Functional Patterns
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::Util
 

Recently uploaded

Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 

Recently uploaded (20)

Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 

Super Advanced Python –act1

  • 1. Super Advanced Python –act1 https://www.spkrbar.com/talk/11 參考Raymond Chandler III演講
  • 2. Built-in Functions abs() divmod() input() open() staticmethod() all() enumerate() int() ord() str() any() eval() isinstance() pow() sum() basestring() execfile() issubclass() print() super() bin() file() iter() property() tuple() bool() filter() len() range() type() bytearray() float() list() raw_input() unichr() callable() format() locals() reduce() unicode() chr() frozenset() long() reload() vars() classmethod() getattr() map() repr() xrange() cmp() globals() max() reversed() zip() compile() hasattr() memoryvie w() round() __import__() complex() hash() min() set() apply() delattr() help() next() setattr() buffer() dict() hex() object() slice() coerce() dir() id() oct() sorted() intern()
  • 3. Built-in Functions • 內建型態(Built-in type) – 數值型態(Numeric type) - int, long, float, bool, complex – 字串型態(String type) • 補充format >>> '%(real)s is %(nick)s' % {'real' : 'Justin', 'nick' : 'caterpillar'} 'Justin is caterpillar‘ >>> '{0} is {1}'.format('Justin', 'caterpillar') 'Justin is caterpillar' – 容器型態(Container type) - list, set, dict, tuple
  • 4. 三種基本type • list 型態 • set 型態 • dict 型態 • tuple 型態
  • 5. List comprehension • list = [1,2,3,4,5] {1: 10, 2: 20, 3: 30, 4: 40, 5: 50} {1: 10, 2: 20, 3: 30, 4: 40, 5: 50} [(1, 10), (2, 20), (3, 30), (4, 40), (5, 50)] [(1, 100), (2, 200), (3, 300), (4, 400), (5, 500)] {1: 11, 2: 21, 3: 31, 4: 41, 5: 51} {'a': 2, 'c': 6, 'b': 4} print(dict([(v,v*10)for v in list])) print({v:v*10 for v in list}) my_dict = {v:v*10 for v in list} print(my_dict.items()) result = [(k,v*10) for (k,v) in my_dict.items()] print(result) dict_compr = {k:v+1 for k,v in my_dict.items()} print(dict_compr) # correct method my_dicts = {'a':1 ,'b':2, 'c':3} print({k:v*2 for k, v in my_dicts.items()}) Items(): #return (key, value) pairs 還有iterkeys(), itervalues(), iteritems()
  • 6. Dict comprehension • my_dicts = {'a':1 ,'b':2, 'c':3} result = {k:v*2 for k, v in my_dicts.items()} print(result) print(result.iterkeys()) print(result.itervalues()) print(result.iteritems()) pairs1 = zip(result.iterkeys(),result.itervalues()) print(pairs1,type(pairs1)) pairs2 = [(v,k) for (k,v) in result.iteritems()] print(pairs2,type(pairs2)) {'a': 2, 'c': 6, 'b': 4} <dictionary-keyiterator object at 0x7f3bd764c940> <dictionary-valueiterator object at 0x7f3bd764c940> <dictionary-itemiterator object at 0x7f3bd764c940> ([('a', 2), ('c', 6), ('b', 4)], <type 'list'>) ([(2, 'a'), (6, 'c'), (4, 'b')], <type 'list'>)
  • 7. Lambda • my_list = [1,2,3,4,5] def my_func(item): return item *2 print([my_func(x) for x in my_list]) other_func = lambda x: x*2 print([other_func(x) for x in my_list]) print(map(lambda i:i*2,my_list)) print(map(lambda i:i*i,my_list)) [2, 4, 6, 8, 10] [2, 4, 6, 8, 10] [2, 4, 6, 8, 10] [1, 4, 9, 16, 25]
  • 8. Enumerate • my_first_list = ['a', 'b', 'c', 'd', 'e'] my_second_list = [1,2,3,4,5] print(zip(my_first_list, my_second_list)) print(enumerate(my_first_list)) print(enumerate(my_first_list, 3)) for i,j in enumerate(my_first_list,1): print(i,j) print([(i,j) for i,j in enumerate(my_first_list,1)]) [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)] <enumerate object at 0x7f3bd764d870> <enumerate object at 0x7f3bd764d870> (1, 'a') (2, 'b') (3, 'c') (4, 'd') (5, 'e') [(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')]
  • 9. zip • my_first_list = "abcde" my_second_list = "zyxwv" result = zip(my_first_list, my_second_list) print(result) result2 = [''.join(x) for x in result] print(result2) result3 = ['123'.join(x) for x in result] print(result3) print(dict(result)) print([(k*3,v) for k,v in result]) [('a', 'z'), ('b', 'y'), ('c', 'x'), ('d', 'w'), ('e', 'v')] ['az', 'by', 'cx', 'dw', 'ev'] ['a123z', 'b123y', 'c123x', 'd123w', 'e123v'] {'a': 'z', 'c': 'x', 'b': 'y', 'e': 'v', 'd': 'w'} [('aaa', 'z'), ('bbb', 'y'), ('ccc', 'x'), ('ddd', 'w'), ('eee', 'v')]
  • 10. filter • my_list = [1,2,3,4,5,6] print([x for x in my_list if x % 2 == 0]) print(filter(lambda x: x % 2 == 0, my_list)) #filter(function, iterable) [2, 4, 6] [2, 4, 6]
  • 11. Any / all • my_list = [True,False,False,False] print(any(my_list)) print(all(my_list)) my_list2 = [True,True,True] print(any(my_list2)) print(all(my_list2)) True False True True
  • 12. • all(iterable)Return True if all elements of the iterable are true (or if the iterable is empty). Equivalent to: • def all(iterable): for element in iterable: if not element: return False return True • any(iterable)Return True if any element of the iterable is true. If the iterable is empty, return False. Equivalent to: • def any(iterable): for element in iterable: if element: return True return False
  • 13. map • my_list = range(1,7) #range(start, stop[, step]) print(my_list) print([x *2 for x in my_list]) range(): #range(start, stop[, step]) print(map(lambda x:x *2 , my_list)) [1, 2, 3, 4, 5, 6] [2, 4, 6, 8, 10, 12] [2, 4, 6, 8, 10, 12]
  • 14. reduce • val = 0 for x in range(1,7): val += x print(val) print(reduce(lambda x,y: x+y, range(1,7))) print(reduce(lambda x,y: x*y, range(1,7))) print(sum(range(1,7))) 21 21 720 21
  • 15. 參考網頁 • http://www.codedata.com.tw/python/python-tutorial-the-2nd-class- 2-container-flow-for-comprehension/ • http://54im.com/python/%E3%80%90python-2-73-1- %E6%96%B0%E7%89%B9%E6%80%A7%E3%80%91%E5%AD%97%E 5%85%B8%E6%8E%A8%E5%AF%BC%E5%BC%8F%EF%BC%88dictio nary-comprehensions%EF%BC%89.html • https://docs.python.org/2/library/stdtypes.html?highlight=dict#dict .items • http://pydoing.blogspot.tw/2011/02/python-enumerate.html • http://pydoing.blogspot.tw/2011/03/python-strjoin.html • http://pydoing.blogspot.tw/2011/02/python-filter.html • https://docs.python.org/2/library/functions.html#all • https://docs.python.org/2/library/functions.html#reduce • https://www.spkrbar.com/talk/11