SlideShare a Scribd company logo
1 of 15
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
 
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
大量地区化解决方案V5bqconf
 
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 ChedeauReact London 2017
 
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
 
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 IIDr. 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 BootstrapHoward 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 practiceTobias Pfeiffer
 
Gearman, from the worker's perspective
Gearman, from the worker's perspectiveGearman, from the worker's perspective
Gearman, from the worker's perspectiveBrian Aker
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScriptniklal
 

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

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.contribTzu-ping Chung
 
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 deadlinesMarkus Zapke-Gründemann
 
NoSql Day - Apertura
NoSql Day - AperturaNoSql Day - Apertura
NoSql Day - AperturaWEBdeBS
 
Rabbitmq & Postgresql
Rabbitmq & PostgresqlRabbitmq & Postgresql
Rabbitmq & PostgresqlLucio 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 pythonJiho Lee
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - ChiusuraWEBdeBS
 
라이트닝 토크 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 PyconJacqueline Kazil
 
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-toturialWayne 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.7decoupled
 
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 TricksBryan 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
 
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
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a ElixirSvet 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 apitrygvea
 
Scala Functional Patterns
Scala Functional PatternsScala Functional Patterns
Scala Functional Patternsleague
 
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::UtilNova 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

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...software pro Development
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 

Recently uploaded (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 

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