Useful Python Odds and Ends Online Data String Functions
[Pages:21]Useful Python Odds and Ends
Online Data String Functions
Mar 17, 2016
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
1
HW Schedule
? Today (HW 2-7 out) : Build concordance
? Hardest so far!
? This Thursday: Extra concordance functions
? Much more manageable
? Next Tuesday: Last HW (2-8) on Python
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
2
Review: More Python Dictionaries
? Open today's activity, ACT 2-6 ? In Task 1, download and save ACT2-6.py
? You have a dictionary called passwordDictionary
? Print it:
? >>> printDictionary(passwordDictionary)
? Let's now modify it to make it sorted
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
3
Review: More Python Dictionaries
? REMEMBER: Keys Are Unique ? REMEMBER: Key/Value pairs are Unordered
Function/Syntax keys() values() in
del([])
Input None
None
None
Dict. Entry
Output Example
List of keys List of values Boolean
None
>>> freq.keys() ['the', 'cat']
>>> freq2.values() [3, 2]
>>> 'the' in freq2 True
>>> del(freq2[`cat'])
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
4
How to do it
def printDictionary(dictionary): '''Prints dictionary key-value pairs ''' keyList = sorted(dictionary.keys()) for key in keyList: print(key,' -> ',dictionary[key]) return
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
5
Making Things Interactive
? Programs often need to obtain input from the user
? input(prompt) Python function
? Run our example in the activity: ? echo()function
def echo(): myInput = input('write something... ') print('You wrote:',myInput) return
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
6
Making Things Interactive
? Change the addPassword function:
def addPassword(dictionary,key,value): print('Changing Password.') dictionary[key] = value return dictionary
To test the function:
addPassword(passwordDictionary, 'Me' , '123456')
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
7
Making Things Interactive
First step: warning on change
def addPassword(dictionary,key,value): print('Changing Password.') if key in dictionary: print('Warning: overwriting data!') dictionary[key] = value return dictionary
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
8
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- useful python odds and ends online data string functions
- unicode in python
- phương thức string decode trong python
- overcoming frustration correctly using unicode in python
- pattern matching and text manipulation bram kuijper
- programming with unicode documentation
- python data persistence tutorialspoint
- python string code rxjs ggplot2 python data
Related searches
- ms access string functions vba
- c string functions examples
- string functions in access 2016
- useful python scripts
- java string functions examples
- string functions in java
- javascript string functions w3
- python commands and functions pdf
- string functions excel
- string functions in tableau
- string functions tableau
- string functions in python