SlideShare a Scribd company logo
1 of 19
Download to read offline
1plo
Python – Dictionary and Loops
Mahalakshmi Arulalan
maharulalan@gmail.com
Sets
>>> thisset = {"apple", "banana", "cherry"}
print(thisset)
>>> thisset.add("orange")
>>> thisset.update(["orange", "mango",
"grapes"])
>>> thisset.copy() //Returns a copy of the set
>>> thisset.discard("banana") // Remove the
specified item
>>> discard() Remove the specified item
>>> thisset.add("orange")
thisset = {"apple", "banana", "cherry"}
>>> thisset.update(["orange", "mango",
"grapes"])
print(thisset)
String
name = 'Arul'
name[0]
>>>'A'
myname = 'Arul' + 'alan'
>>> 'Arulalan'
name = 'This is python string'
name.split(' ')
>>>['This','is','python','string']
comma = 'Shrini,Arul,Suresh'
comma.split(',')
>>> ['Shrini','Arul','Suresh']
split
li = ['a','b','c','d']
s = '-'
new = s.join(li)
>>> a-b-c-d
new.split('-')
>>>['a','b','c','d']
join
'small'.upper()
>>>'SMALL'
'BIG'.lower()
>>> 'big'
'mIxEd'.swapcase()
>>>'MiXwD'
Dictionary
menu = {
“idly” : 2.50,
“dosai” : 10.00,
“coffee” : 5.00,
“ice_cream” : 5.00,
100 : “Hundred”
}
menu[“idly”]
2.50
menu[100]
Hundred
Loop
for i in range(1, 5):
print i
print 'The for loop is over'
for i in ["apple", "banana", "cherry"]:
print i
print 'The for loop is over'
for i in range(1, 5):
for j in range (10,20):
print i,j
print 'The for loop is over'
number = 23
running = True
while running :
guess = int(raw_input('Enter an integer : '))
if guess == number :
print 'Congratulations, you guessed it.'
running = False
elif guess < number :
print 'No, it is a little higher than that.'
else:
print 'No, it is a little lower than that.'
print 'Done'
number = 23
while True :
guess = int(raw_input('Enter an integer : '))
if guess == number :
print 'Congratulations, you guessed it.'
break
elif guess < number :
print 'No, it is a little higher than that.'
else:
print 'No, it is a little lower than that.'
print 'Done'
Single Line if, for loop
End of the Day three.

More Related Content

What's hot

บทที่6 update&delete
บทที่6 update&deleteบทที่6 update&delete
บทที่6 update&delete
Palm Unnop
 
Magicke metody v Pythonu
Magicke metody v PythonuMagicke metody v Pythonu
Magicke metody v Pythonu
Jirka Vejrazka
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cython
Anderson Dantas
 
Python data structures
Python data structuresPython data structures
Python data structures
Harry Potter
 

What's hot (14)

บทที่6 update&delete
บทที่6 update&deleteบทที่6 update&delete
บทที่6 update&delete
 
Magicke metody v Pythonu
Magicke metody v PythonuMagicke metody v Pythonu
Magicke metody v Pythonu
 
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of WranglingPLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
 
{:from => 'Java', :to => 'Ruby'}
{:from => 'Java', :to => 'Ruby'}{:from => 'Java', :to => 'Ruby'}
{:from => 'Java', :to => 'Ruby'}
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cython
 
Python - Lecture 3
Python - Lecture 3Python - Lecture 3
Python - Lecture 3
 
Chap 3php array part 3
Chap 3php array part 3Chap 3php array part 3
Chap 3php array part 3
 
Python data structures
Python data structuresPython data structures
Python data structures
 
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicitElixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
 
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicitElixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
 
FITC CoffeeScript 101
FITC CoffeeScript 101FITC CoffeeScript 101
FITC CoffeeScript 101
 
Begin with Python
Begin with PythonBegin with Python
Begin with Python
 
Association Rule Mining with R
Association Rule Mining with RAssociation Rule Mining with R
Association Rule Mining with R
 
The Ring programming language version 1.5.1 book - Part 50 of 180
The Ring programming language version 1.5.1 book - Part 50 of 180The Ring programming language version 1.5.1 book - Part 50 of 180
The Ring programming language version 1.5.1 book - Part 50 of 180
 

More from MAHALAKSHMI P

Sex education,பாலியல் கல்வி ,paaliyal kalvi,good touch bad touch
Sex education,பாலியல் கல்வி ,paaliyal kalvi,good touch bad touchSex education,பாலியல் கல்வி ,paaliyal kalvi,good touch bad touch
Sex education,பாலியல் கல்வி ,paaliyal kalvi,good touch bad touch
MAHALAKSHMI P
 

More from MAHALAKSHMI P (13)

Python an-intro youtube-livestream-day4
Python an-intro youtube-livestream-day4Python an-intro youtube-livestream-day4
Python an-intro youtube-livestream-day4
 
Python an-intro youtube-livestream-day2
Python an-intro youtube-livestream-day2Python an-intro youtube-livestream-day2
Python an-intro youtube-livestream-day2
 
Python an-intro youtube-livestream-day1
Python an-intro youtube-livestream-day1Python an-intro youtube-livestream-day1
Python an-intro youtube-livestream-day1
 
double linked list
double linked listdouble linked list
double linked list
 
linked list operations in data structures
linked list operations in data structureslinked list operations in data structures
linked list operations in data structures
 
singly linked_list
singly linked_listsingly linked_list
singly linked_list
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
arrays in data structures
arrays in data structuresarrays in data structures
arrays in data structures
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Data structures- introduction1
Data structures-  introduction1Data structures-  introduction1
Data structures- introduction1
 
Python_in_Detail
Python_in_DetailPython_in_Detail
Python_in_Detail
 
Sex education,பாலியல் கல்வி ,paaliyal kalvi,good touch bad touch
Sex education,பாலியல் கல்வி ,paaliyal kalvi,good touch bad touchSex education,பாலியல் கல்வி ,paaliyal kalvi,good touch bad touch
Sex education,பாலியல் கல்வி ,paaliyal kalvi,good touch bad touch
 
Seminar on sunday
Seminar on sundaySeminar on sunday
Seminar on sunday
 

Recently uploaded

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 

Recently uploaded (20)

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 

Python an-intro youtube-livestream-day3

  • 1. 1plo Python – Dictionary and Loops Mahalakshmi Arulalan maharulalan@gmail.com
  • 3. >>> thisset = {"apple", "banana", "cherry"} print(thisset) >>> thisset.add("orange") >>> thisset.update(["orange", "mango", "grapes"]) >>> thisset.copy() //Returns a copy of the set >>> thisset.discard("banana") // Remove the specified item
  • 4. >>> discard() Remove the specified item >>> thisset.add("orange") thisset = {"apple", "banana", "cherry"} >>> thisset.update(["orange", "mango", "grapes"]) print(thisset)
  • 6. name = 'Arul' name[0] >>>'A' myname = 'Arul' + 'alan' >>> 'Arulalan'
  • 7. name = 'This is python string' name.split(' ') >>>['This','is','python','string'] comma = 'Shrini,Arul,Suresh' comma.split(',') >>> ['Shrini','Arul','Suresh'] split
  • 8. li = ['a','b','c','d'] s = '-' new = s.join(li) >>> a-b-c-d new.split('-') >>>['a','b','c','d'] join
  • 11. menu = { “idly” : 2.50, “dosai” : 10.00, “coffee” : 5.00, “ice_cream” : 5.00, 100 : “Hundred” } menu[“idly”] 2.50 menu[100] Hundred
  • 12. Loop
  • 13. for i in range(1, 5): print i print 'The for loop is over'
  • 14. for i in ["apple", "banana", "cherry"]: print i print 'The for loop is over'
  • 15. for i in range(1, 5): for j in range (10,20): print i,j print 'The for loop is over'
  • 16. number = 23 running = True while running : guess = int(raw_input('Enter an integer : ')) if guess == number : print 'Congratulations, you guessed it.' running = False elif guess < number : print 'No, it is a little higher than that.' else: print 'No, it is a little lower than that.' print 'Done'
  • 17. number = 23 while True : guess = int(raw_input('Enter an integer : ')) if guess == number : print 'Congratulations, you guessed it.' break elif guess < number : print 'No, it is a little higher than that.' else: print 'No, it is a little lower than that.' print 'Done'
  • 18. Single Line if, for loop
  • 19. End of the Day three.