SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
Python Basics
- python is a dynamic, interpreted, object
oriented programming language
- source code does not declare the types
of variables, or parameters or methods
Static: Dynamic:
static int a_number; a_number = 42
a_number = 42;
Python Basics
- readable, flexible code
- lose the compile-time type checking in
the source code; higher productivity
- code is checked at runtime
Python Interpreter
- good for learning the language
- good for experimenting with the library
- helpful functions: dir(), help()
Python Variables
radius = 4
pi = 3.14
area = pi * radius * radius
Python Strings
- python string are immutable
spell = 'abrakadabra'
len(spell) >>> 11
a = Python
'Hello %s' %a >>> 'Hello Python'
a.lower() >>> 'python'
a.find('t') >>> 2
a[start:end]
Python Indentation
def fib(n):
print 'n=', n
if n > 1:
return n * fib(n-1)
else:
print 'end of line'
return 1
Python If Statement
- python does not use { } to enclose blocks of code for
if/loops/function etc.
- uses the colon “:” and indentation/whitespace to
group statements
- '==' is overloaded to work correctly with strings
if speed > 80:
print 'License and registration please'
if mood == 'terrible' or speed >= 100:
print 'You have the right to remain silent'
elif mood == 'bad' or speed >=90:
print “I'm going to have to give you a ticket”
else:
print “Let's keep it under 80, ok?”
Python For Statement
for x in range(5):
print x
for x in xrange(10):
if x % 2 == 0:
continue
print x
primes = [2, 3, 5, 7]
for prime in primes:
print prime
Python For Statement
for x in range(2, n):
if n % x == 0:
print n, 'equals', x, '*', n/x
break
else:
print n, 'is a prime number'
Exercises:
1. Write a program that asks two people for their names;
stores the names in variables; says hello to both of them.
Use "raw_input". Don't use "+" for string concatenation.
2. Write a program that asks users for their favorite color.
Create the following output (assuming "red" is the chosen
color).
red red red red red red red red red red
red red
red red
red red red red red red red red red red
3 .print all multiples of 13 that are smaller than 100.
Python Lists
pets = [2, 'dogs', ['and', 'one', 'cat']]
pets[1] >>> dogs
pets[2] >>> ['and', 'one', 'cat']
a = [4, 1, 2, 6]
sorted(a) >>> [1, 2, 4, 6]
a = ['aaaz', 'cc', 'd', 'bbb']
b = ':'.join(a) >>> 'aaaz:cc:d:bbb'
b.split(':') >>> ['aaaz', 'cc', 'd', 'bbb']
Python Tuples
- tuples are immutable
- fixed size
a = (1, 2, 3)
Exercises
1. Create a list that contains the names of 5 students.
Create a for loop that asks the user for every name whether
they would like to keep the name or delete it. Delete the
names which the user no longer wants
2. Given a list of strings, return the count of the number of
strings where the string length is 2 or more and the first
and last chars of the string are the same.
3 . Given a list of strings, return a list with the strings
in sorted order, except group all the strings that begin with
'x' first.
eg. ['mix', 'xyz', 'apple', 'xanadu', 'aardvark'] >>>
['xanadu', 'xyz', 'aardvark', 'apple', 'mix']
Python Dictionaries
- also known as associative arrays or
hash tables
- dictionaries consist of pairs of keys and
their corresponding values.
- strings, numbers, and tuples work as
keys, and any type can be a value
Python Dictionaries
d = {'a': 'alpha', 'o': 'omega', 'g': 'gamma'}
d['o'] >>> 'omega'
d['b']
d.get('b')
d.keys() >>> ['a', 'g', 'o']
d.values() >>> ['alpha', 'gamma', 'omega']
d.items() >>> [('a', 'alpha'), ('g', 'gamma'), ('o', 'omega')]
Exercises
1. given a string "abbabcbdbabdbdbabababcbcbab",
construct a dictionary containing letter frequency in the
string.

Weitere ähnliche Inhalte

Was ist angesagt?

Python unit 2 M.sc cs
Python unit 2 M.sc csPython unit 2 M.sc cs
Python unit 2 M.sc csKALAISELVI P
 
Sequence Types in Python Programming
Sequence Types in Python ProgrammingSequence Types in Python Programming
Sequence Types in Python ProgrammingBobby Murugesan
 
Python :variable types
Python :variable typesPython :variable types
Python :variable typesS.M. Salaquzzaman
 
Python language data types
Python language data typesPython language data types
Python language data typesHoang Nguyen
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
Standard data-types-in-py
Standard data-types-in-pyStandard data-types-in-py
Standard data-types-in-pyPriyanshu Sengar
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in pythoneShikshak
 
Basics of Python
Basics of PythonBasics of Python
Basics of PythonEase3
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for KidsAimee Maree Forsstrom
 
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
 
Iteration
IterationIteration
IterationPooja B S
 
Python course Day 1
Python course Day 1Python course Day 1
Python course Day 1Karin Lagesen
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 

Was ist angesagt? (18)

Python
PythonPython
Python
 
Chapter 14 strings
Chapter 14 stringsChapter 14 strings
Chapter 14 strings
 
Python unit 2 M.sc cs
Python unit 2 M.sc csPython unit 2 M.sc cs
Python unit 2 M.sc cs
 
Sequence Types in Python Programming
Sequence Types in Python ProgrammingSequence Types in Python Programming
Sequence Types in Python Programming
 
Python :variable types
Python :variable typesPython :variable types
Python :variable types
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Pythonintroduction
PythonintroductionPythonintroduction
Pythonintroduction
 
Standard data-types-in-py
Standard data-types-in-pyStandard data-types-in-py
Standard data-types-in-py
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Basics of Python
Basics of PythonBasics of Python
Basics of Python
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for Kids
 
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!
 
Iteration
IterationIteration
Iteration
 
Python course Day 1
Python course Day 1Python course Day 1
Python course Day 1
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 

Ă„hnlich wie Python tutorial

Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
 
Module 3 - Regular Expressions, Dictionaries.pdf
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdfGaneshRaghu4
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfpaijitk
 
Introduction to Python Basics
Introduction to Python BasicsIntroduction to Python Basics
Introduction to Python BasicsRaghunath A
 
Python basics
Python basicsPython basics
Python basicsHoang Nguyen
 
Python basics
Python basicsPython basics
Python basicsTony Nguyen
 
Python basics
Python basicsPython basics
Python basicsYoung Alista
 
Python basics
Python basicsPython basics
Python basicsHarry Potter
 
Python basics
Python basicsPython basics
Python basicsFraboni Ec
 
Python basics
Python basicsPython basics
Python basicsJames Wong
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxCatherineVania1
 
Ry pyconjp2015 turtle
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtleRenyuan Lyu
 

Ă„hnlich wie Python tutorial (20)

Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Python basic
Python basicPython basic
Python basic
 
Module 3 - Regular Expressions, Dictionaries.pdf
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdf
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdf
 
Introduction to Python Basics
Introduction to Python BasicsIntroduction to Python Basics
Introduction to Python Basics
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python slide.1
Python slide.1Python slide.1
Python slide.1
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
 
Python basics
Python basicsPython basics
Python basics
 
Ry pyconjp2015 turtle
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtle
 
Python
PythonPython
Python
 

KĂĽrzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

KĂĽrzlich hochgeladen (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Python tutorial

  • 1. Python Basics - python is a dynamic, interpreted, object oriented programming language - source code does not declare the types of variables, or parameters or methods Static: Dynamic: static int a_number; a_number = 42 a_number = 42;
  • 2. Python Basics - readable, flexible code - lose the compile-time type checking in the source code; higher productivity - code is checked at runtime
  • 3. Python Interpreter - good for learning the language - good for experimenting with the library - helpful functions: dir(), help()
  • 4. Python Variables radius = 4 pi = 3.14 area = pi * radius * radius
  • 5. Python Strings - python string are immutable spell = 'abrakadabra' len(spell) >>> 11 a = Python 'Hello %s' %a >>> 'Hello Python' a.lower() >>> 'python' a.find('t') >>> 2 a[start:end]
  • 6. Python Indentation def fib(n): print 'n=', n if n > 1: return n * fib(n-1) else: print 'end of line' return 1
  • 7. Python If Statement - python does not use { } to enclose blocks of code for if/loops/function etc. - uses the colon “:” and indentation/whitespace to group statements - '==' is overloaded to work correctly with strings if speed > 80: print 'License and registration please' if mood == 'terrible' or speed >= 100: print 'You have the right to remain silent' elif mood == 'bad' or speed >=90: print “I'm going to have to give you a ticket” else: print “Let's keep it under 80, ok?”
  • 8. Python For Statement for x in range(5): print x for x in xrange(10): if x % 2 == 0: continue print x primes = [2, 3, 5, 7] for prime in primes: print prime
  • 9. Python For Statement for x in range(2, n): if n % x == 0: print n, 'equals', x, '*', n/x break else: print n, 'is a prime number'
  • 10. Exercises: 1. Write a program that asks two people for their names; stores the names in variables; says hello to both of them. Use "raw_input". Don't use "+" for string concatenation. 2. Write a program that asks users for their favorite color. Create the following output (assuming "red" is the chosen color). red red red red red red red red red red red red red red red red red red red red red red red red 3 .print all multiples of 13 that are smaller than 100.
  • 11. Python Lists pets = [2, 'dogs', ['and', 'one', 'cat']] pets[1] >>> dogs pets[2] >>> ['and', 'one', 'cat'] a = [4, 1, 2, 6] sorted(a) >>> [1, 2, 4, 6] a = ['aaaz', 'cc', 'd', 'bbb'] b = ':'.join(a) >>> 'aaaz:cc:d:bbb' b.split(':') >>> ['aaaz', 'cc', 'd', 'bbb']
  • 12. Python Tuples - tuples are immutable - fixed size a = (1, 2, 3)
  • 13. Exercises 1. Create a list that contains the names of 5 students. Create a for loop that asks the user for every name whether they would like to keep the name or delete it. Delete the names which the user no longer wants 2. Given a list of strings, return the count of the number of strings where the string length is 2 or more and the first and last chars of the string are the same. 3 . Given a list of strings, return a list with the strings in sorted order, except group all the strings that begin with 'x' first. eg. ['mix', 'xyz', 'apple', 'xanadu', 'aardvark'] >>> ['xanadu', 'xyz', 'aardvark', 'apple', 'mix']
  • 14. Python Dictionaries - also known as associative arrays or hash tables - dictionaries consist of pairs of keys and their corresponding values. - strings, numbers, and tuples work as keys, and any type can be a value
  • 15. Python Dictionaries d = {'a': 'alpha', 'o': 'omega', 'g': 'gamma'} d['o'] >>> 'omega' d['b'] d.get('b') d.keys() >>> ['a', 'g', 'o'] d.values() >>> ['alpha', 'gamma', 'omega'] d.items() >>> [('a', 'alpha'), ('g', 'gamma'), ('o', 'omega')]
  • 16. Exercises 1. given a string "abbabcbdbabdbdbabababcbcbab", construct a dictionary containing letter frequency in the string.