SlideShare a Scribd company logo

Super Advanced Python –act1

The document discusses various built-in functions in Python including numeric, string, and container data types. It provides examples of using list comprehensions, dictionary comprehensions, lambda functions, enumerate, zip, filter, any, all, map and reduce to manipulate data in Python. It also includes references to online resources for further reading.

1 of 15
Download to read offline
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'>)

Recommended

Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)MongoSF
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Baruch Sadogursky
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cythonAnderson Dantas
 
Useful javascript
Useful javascriptUseful javascript
Useful javascriptLei Kang
 

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
 
---------IN PYTHON------------ 1- (60pts) Let's assume that there are.pdf
---------IN PYTHON------------ 1- (60pts) Let's assume that there are.pdf---------IN PYTHON------------ 1- (60pts) Let's assume that there are.pdf
---------IN PYTHON------------ 1- (60pts) Let's assume that there are.pdfsyedazmath9
 
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
 

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
 
---------IN PYTHON------------ 1- (60pts) Let's assume that there are.pdf
---------IN PYTHON------------ 1- (60pts) Let's assume that there are.pdf---------IN PYTHON------------ 1- (60pts) Let's assume that there are.pdf
---------IN PYTHON------------ 1- (60pts) Let's assume that there are.pdf
 
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
 

Recently uploaded

Passbolt Introduction and Usage for secret managment
Passbolt Introduction and Usage for secret managmentPassbolt Introduction and Usage for secret managment
Passbolt Introduction and Usage for secret managmentThierry Gayet
 
killing camp 주차장 나누기-2 topology sort.pdf
killing camp 주차장 나누기-2 topology sort.pdfkilling camp 주차장 나누기-2 topology sort.pdf
killing camp 주차장 나누기-2 topology sort.pdfssuser82c38d
 
Role of DevOps in SaaS product Development.pdf.pptx
Role of DevOps in SaaS product Development.pdf.pptxRole of DevOps in SaaS product Development.pdf.pptx
Role of DevOps in SaaS product Development.pdf.pptxMindInventory
 
Joseph Yoder : Being Agile about Architecture
Joseph Yoder : Being Agile about ArchitectureJoseph Yoder : Being Agile about Architecture
Joseph Yoder : Being Agile about ArchitectureHironori Washizaki
 
LLMOps with Azure Machine Learning prompt flow
LLMOps with Azure Machine Learning prompt flowLLMOps with Azure Machine Learning prompt flow
LLMOps with Azure Machine Learning prompt flowNaoki (Neo) SATO
 
Orion Context Broker introduction 20240227
Orion Context Broker introduction 20240227Orion Context Broker introduction 20240227
Orion Context Broker introduction 20240227Fermin Galan
 
Automation for Bonterra Impact Management (fka Apricot)
Automation for Bonterra Impact Management (fka Apricot)Automation for Bonterra Impact Management (fka Apricot)
Automation for Bonterra Impact Management (fka Apricot)Jeffrey Haguewood
 
Workshop híbrido: Stream Processing con Flink
Workshop híbrido: Stream Processing con FlinkWorkshop híbrido: Stream Processing con Flink
Workshop híbrido: Stream Processing con Flinkconfluent
 
Welcome to AltTask - the nexus where innovation converges with empowerment!
Welcome to AltTask - the nexus where innovation converges with empowerment!Welcome to AltTask - the nexus where innovation converges with empowerment!
Welcome to AltTask - the nexus where innovation converges with empowerment!alttaskcom
 
Alluxio Monthly Webinar | Why a Multi-Cloud Strategy Matters for Your AI Plat...
Alluxio Monthly Webinar | Why a Multi-Cloud Strategy Matters for Your AI Plat...Alluxio Monthly Webinar | Why a Multi-Cloud Strategy Matters for Your AI Plat...
Alluxio Monthly Webinar | Why a Multi-Cloud Strategy Matters for Your AI Plat...Alluxio, Inc.
 
The Top Outages of 2023: Analyses and Takeaways
The Top Outages of 2023: Analyses and TakeawaysThe Top Outages of 2023: Analyses and Takeaways
The Top Outages of 2023: Analyses and TakeawaysThousandEyes
 
How AI is preventing account fraud at web scale
How AI is preventing account fraud at web scaleHow AI is preventing account fraud at web scale
How AI is preventing account fraud at web scaleAmir Moghimi
 
killingcamp longest common subsequence.pdf
killingcamp longest common subsequence.pdfkillingcamp longest common subsequence.pdf
killingcamp longest common subsequence.pdfssuser82c38d
 
Machine Learning Basics for Dummies (no math!)
Machine Learning Basics for Dummies (no math!)Machine Learning Basics for Dummies (no math!)
Machine Learning Basics for Dummies (no math!)Dmitry Zinoviev
 
No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!Anthony Dahanne
 
Design pattern talk by Kaya Weers - 2024
Design pattern talk by Kaya Weers - 2024Design pattern talk by Kaya Weers - 2024
Design pattern talk by Kaya Weers - 2024Kaya Weers
 
Cybersecurity Measures For Remote Workers.pdf
Cybersecurity Measures For Remote Workers.pdfCybersecurity Measures For Remote Workers.pdf
Cybersecurity Measures For Remote Workers.pdfCIOWomenMagazine
 
CSS Notes in PDF, Easy to understand. For beginner to advanced. ...
CSS Notes in PDF, Easy to understand. For beginner to advanced.              ...CSS Notes in PDF, Easy to understand. For beginner to advanced.              ...
CSS Notes in PDF, Easy to understand. For beginner to advanced. ...syedfaisal759877
 
What are the Reasons for Tracking the Attendance of the Employees?
What are the Reasons for Tracking the Attendance of the Employees?What are the Reasons for Tracking the Attendance of the Employees?
What are the Reasons for Tracking the Attendance of the Employees?NYGGS Automation Suite
 

Recently uploaded (20)

Passbolt Introduction and Usage for secret managment
Passbolt Introduction and Usage for secret managmentPassbolt Introduction and Usage for secret managment
Passbolt Introduction and Usage for secret managment
 
killing camp 주차장 나누기-2 topology sort.pdf
killing camp 주차장 나누기-2 topology sort.pdfkilling camp 주차장 나누기-2 topology sort.pdf
killing camp 주차장 나누기-2 topology sort.pdf
 
Role of DevOps in SaaS product Development.pdf.pptx
Role of DevOps in SaaS product Development.pdf.pptxRole of DevOps in SaaS product Development.pdf.pptx
Role of DevOps in SaaS product Development.pdf.pptx
 
Joseph Yoder : Being Agile about Architecture
Joseph Yoder : Being Agile about ArchitectureJoseph Yoder : Being Agile about Architecture
Joseph Yoder : Being Agile about Architecture
 
LLMOps with Azure Machine Learning prompt flow
LLMOps with Azure Machine Learning prompt flowLLMOps with Azure Machine Learning prompt flow
LLMOps with Azure Machine Learning prompt flow
 
Orion Context Broker introduction 20240227
Orion Context Broker introduction 20240227Orion Context Broker introduction 20240227
Orion Context Broker introduction 20240227
 
Automation for Bonterra Impact Management (fka Apricot)
Automation for Bonterra Impact Management (fka Apricot)Automation for Bonterra Impact Management (fka Apricot)
Automation for Bonterra Impact Management (fka Apricot)
 
Workshop híbrido: Stream Processing con Flink
Workshop híbrido: Stream Processing con FlinkWorkshop híbrido: Stream Processing con Flink
Workshop híbrido: Stream Processing con Flink
 
Welcome to AltTask - the nexus where innovation converges with empowerment!
Welcome to AltTask - the nexus where innovation converges with empowerment!Welcome to AltTask - the nexus where innovation converges with empowerment!
Welcome to AltTask - the nexus where innovation converges with empowerment!
 
2024 Trends Transforming Enterprise Resource Planning
2024 Trends Transforming Enterprise Resource Planning2024 Trends Transforming Enterprise Resource Planning
2024 Trends Transforming Enterprise Resource Planning
 
Alluxio Monthly Webinar | Why a Multi-Cloud Strategy Matters for Your AI Plat...
Alluxio Monthly Webinar | Why a Multi-Cloud Strategy Matters for Your AI Plat...Alluxio Monthly Webinar | Why a Multi-Cloud Strategy Matters for Your AI Plat...
Alluxio Monthly Webinar | Why a Multi-Cloud Strategy Matters for Your AI Plat...
 
The Top Outages of 2023: Analyses and Takeaways
The Top Outages of 2023: Analyses and TakeawaysThe Top Outages of 2023: Analyses and Takeaways
The Top Outages of 2023: Analyses and Takeaways
 
How AI is preventing account fraud at web scale
How AI is preventing account fraud at web scaleHow AI is preventing account fraud at web scale
How AI is preventing account fraud at web scale
 
killingcamp longest common subsequence.pdf
killingcamp longest common subsequence.pdfkillingcamp longest common subsequence.pdf
killingcamp longest common subsequence.pdf
 
Machine Learning Basics for Dummies (no math!)
Machine Learning Basics for Dummies (no math!)Machine Learning Basics for Dummies (no math!)
Machine Learning Basics for Dummies (no math!)
 
No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!
 
Design pattern talk by Kaya Weers - 2024
Design pattern talk by Kaya Weers - 2024Design pattern talk by Kaya Weers - 2024
Design pattern talk by Kaya Weers - 2024
 
Cybersecurity Measures For Remote Workers.pdf
Cybersecurity Measures For Remote Workers.pdfCybersecurity Measures For Remote Workers.pdf
Cybersecurity Measures For Remote Workers.pdf
 
CSS Notes in PDF, Easy to understand. For beginner to advanced. ...
CSS Notes in PDF, Easy to understand. For beginner to advanced.              ...CSS Notes in PDF, Easy to understand. For beginner to advanced.              ...
CSS Notes in PDF, Easy to understand. For beginner to advanced. ...
 
What are the Reasons for Tracking the Attendance of the Employees?
What are the Reasons for Tracking the Attendance of the Employees?What are the Reasons for Tracking the Attendance of the Employees?
What are the Reasons for Tracking the Attendance of the Employees?
 

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