Files and Dictionaries

Slides:



Advertisements
Similar presentations
DC Responses Received WA OR ID MT WY CA NV UT CO AZ NM AK HI TX ND SD NE KS OK MN IA MO AR LA WI IL MI IN OH KY TN MS AL GA FL SC NC VA WV PA NY VT NH.
Advertisements

THE COMMONWEALTH FUND Millions of uninsured Source: Income, Poverty, and Health Insurance Coverage in the United States: United States Census Bureau,
Background Information on the Newspoets Total Number: 78 active newspoets. 26 (of the original 36) newspoets from returned this year.
NICS Index State Participation As of 12/31/2007 DC NE NY WI IN NH MD CA NV IL OR TN PA CT ID MT WY ND SD NM KS TX AR OK MN OH WV MSAL KY SC MO ME MA DE.
Essential Health Benefits Benchmark Plan Selection, as of October 2012
Uninsured Non-Elderly Adult Rate Increased from 17. 8% to 20
Medicaid Eligibility for Working Parents by Income, January 2013
House Price
House price index for AK
WY WI WV WA VA VT UT TX TN SD SC RI PA OR* OK OH ND NC NY NM* NJ NH
Files and Dictionaries
Children's Eligibility for Medicaid/CHIP by Income, January 2013
Medicaid Income Eligibility Levels for Other Adults, January 2017
NJ WY WI WV WA VA VT UT TX TN SD SC RI PA OR OK OH ND NC NY NM NH NV
Comprehensive Medicaid Managed Care Models in the States, 2014
Medicaid Costs are Shared by the States and the Federal Government
Expansion states with Republican governors outnumber expansion states with Democratic governors, May 2018 WY WI WV◊ WA VA^ VT UT TX TN SD SC RI PA OR OK.
Expansion states with Republican governors outnumber expansion states with Democratic governors, January WY WI WV◊ WA VA VT UT TX TN SD SC RI PA.
Share of Births Covered by Medicaid, 2006
Non-Citizen Population, by State, 2011
Status of State Medicaid Expansion Decisions
Share of Women Ages 18 – 64 Who Are Uninsured, by State,
Coverage of Low-Income Adults by Scope of Coverage, January 2013
Executive Activity on the Medicaid Expansion Decision, May 9, 2013
WY WI WV WA VA VT UT TX TN1 SD SC RI PA1 OR OK OH ND NC NY NM NJ NH2
WY WI WV WA VA VT UT TX TN1 SD SC RI PA OR OK OH1 ND NC NY NM NJ NH NV
WY WI WV WA VA* VT UT TX TN SD SC RI PA OR* OK OH ND NC NY NM* NJ NH
WY WI WV WA VA VT UT TX TN SD SC RI PA OR* OK OH ND NC NY NM* NJ NH
Mobility Update and Discussion as of March 25, 2008
Current Status of the Medicaid Expansion Decision, as of May 30, 2013
IAH CONVERSION: ELIGIBLE BENEFICIARIES BY STATE
WAHBE Brokers / QHPs across the country as of
619 Involvement in State SSIPs
State Health Insurance Marketplace Types, 2015
State Health Insurance Marketplace Types, 2018
HHGM CASE WEIGHTS Early/Late Mix (Weighted Average)
Status of State Medicaid Expansion Decisions
Status of State Participation in Medicaid Expansion, as of March 2014
Percent of Women Ages 19 to 64 Uninsured by State,
Status of State Medicaid Expansion Decisions
Medicaid Income Eligibility Levels for Parents, January 2017
State Health Insurance Marketplace Types, 2017
S Co-Sponsors by State – May 23, 2014
WY WI WV WA VA VT UT* TX TN SD SC RI PA OR* OK OH ND NC NY NM* NJ NH
Seventeen States Had Higher Uninsured Rates Than the National Average in 2013; Of Those, 11 Have Yet to Expand Eligibility for Medicaid AK NH WA VT ME.
Employer Premiums as Percentage of Median Household Income for Under-65 Population, 2003 and percent of under-65 population live where premiums.
Employer Premiums as Percentage of Median Household Income for Under-65 Population, 2003 and percent of under-65 population live where premiums.
Average annual growth rate
Uninsured Rate Among Adults Ages 19–64, 2008–09 and 2019
Percent of Children Ages 0–17 Uninsured by State
Executive Activity on the Medicaid Expansion Decision, May 9, 2013
Current Status of State Medicaid Expansion Decisions
Current Status of State Medicaid Expansion Decisions
How State Policies Limiting Abortion Coverage Changed Over Time
Post-Reform: Projected Percent of Adults Ages 19–64 Uninsured by State
United States: age distribution family households and family size
Status of State Medicaid Expansion Decisions
Employer Premiums as Percentage of Median Household Income for Under-65 Population, 2003 and percent of under-65 population live where premiums.
Percent of Adults Ages 18–64 Uninsured by State
Uninsured Nonelderly Adult Rate Has Increased from Percent to 20
Files and Dictionaries
States including quality standards in their SSIP improvement strategies for Part C FFY 2013 ( ) States including quality standards in their SSIP.
Status of State Medicaid Expansion Decisions
WY WI WV WA VA VT UT* TX TN SD SC RI PA OR* OK OH ND NC NY NM* NJ NH
WY WI WV WA VA VT UT* TX TN SD SC RI PA OR* OK OH ND NC NY NM* NJ NH
States including their fiscal systems in their SSIP improvement strategies for Part C FFY 2013 ( ) States including their fiscal systems in their.
Current Status of State Individual Marketplace and Medicaid Expansion Decisions, as of September 30, 2013 WY WI WV WA VA VT UT TX TN SD SC RI PA OR OK.
Status of State Medicaid Expansion Decisions
Income Eligibility Levels for Children in Medicaid/CHIP, January 2017
WY WI WV WA VA VT UT TX TN SD SC RI PA OR OK OH ND NC NY NM NJ NH NV
Presentation transcript:

Files and Dictionaries

Files >>> f = open( ‘spam.txt‘, ‘r’ ) In Python reading files is no problem… >>> f = open( ‘spam.txt‘, ‘r’ ) >>> text = f.read() alternative… >>> text = f.read(50) >>> f.close() >>> text 'I like poptarts and 42 and spam.\nWill I ... >>> wordList = text.split() [ 'I', 'like', 'poptarts', ... ] opens the file for reading and calls it f reads the whole file and calls it f reads the next 50 bytes from the file Point out that open is a method on file objects (technically, TextIOStream objects, but stay away from that complexity). And split is a method on string objects. Might want to demonstrate this on the spam.txt file. closes the file (optional) all the text (as one big string) text.split() returns a list of each "word"

>>> f = open( ‘spam.txt‘, ‘w’ ) >>> text = “Hello, world!” >>> f.write(text) >>> f.close() opens the file for writing and calls it f Writes string text to f

Count how many words are in a given file def wc( filename ): """ word-counting program """ f = open( filename, “r”) text = f.read() f.close() words = text.split() print("There are", len(words), "words.") file handling word counting This is in cha6_2.py, but it is the complete function, so you might want to go to the next slide first

Write a function removeDuplicates(somelist) that removes duplicates from the list. Example, alist = [‘hello’, ‘world’, ‘hello’] >>> removeDuplicates(alist) [‘hello’, ‘world’] >>> alist = [‘how’, ‘are’, ‘you’] >>> removeDuplicates[alist) [‘how’, ‘are’, ‘you’]

Dictionaries In Python a dictionary is a set of key - value pairs. >>> d[1992] = 'monkey' >>> d[1993] = 'rooster' >>> d {1992:'monkey', 1993:'rooster'} >>> d[1992] 'monkey' >>> d[1969] key error creates an empty dictionary, d 1992 is the key 'monkey' is the value 1993 is the key 'rooster' is the value Curly! And colony! Retrieve data like lists… It's a sequence where the index can be any immutable key.

More on dictionaries Dictionaries have lots of built-in methods, or functions: >>> d = {1992:'monkey', 1993:'rooster'} >>> 1992 in d >>> 1969 in d True False >>> len(d) 2 >>> list(d.keys()) [ 1992, 1993 ] >>> list(d.values()) [ 'monkey', 'rooster' ] >>> list(d.items()) [ (1992, 'monkey'), (1993, 'rooster') ] in checks if a key is present len returns the # of keys d.keys returns a list of all keys d.values returns a list of all keys d.items returns a list of all key, value pairs

""" word-counting program """ f = open( filename ) text = f.read() What if we wanted the number of different words in the file? This would be the author's vocabulary size, instead of the total word count. def vc( filename ): """ word-counting program """ f = open( filename ) text = f.read() f.close() words = text.split() print("There are", len(words), "words.") d = {} for w in words: if w not in d: d[w] = 1 else: d[w] += 1 print ("There are", len(d), "distinct words.\n“) return len(d) # return the number of distict words file handling word counting Tracking the number of occurences of each word with a dictionary, d. Demo wc() using spam.txt.

Vocabularists? Shakespeare used 31,534 different words and a grand total of 884,647 words counting repetitions (across his works) http://www-math.cudenver.edu/~wbriggs/qr/shakespeare.html Active vocabulary estimates range from 10,000-60,000. Passive vocabulary estimates are much higher. Many Shakespearean contributions: One contemporary author in the Oxford Eng. Dictionary… Shakespeare which word?

Vocabularists? Shakespeare used 31,534 different words and an estimated vocabulary of 66,534 words (across his works) http://kottke.org/10/04/how-many-words-did-shakespeare-know Average English speaker knows 10,000 to 20,000 words. Many Shakespearean contributions: Shakespeare J. K. Rowling

Consider a game of guessing all 50 states… A state challenge… Consider a game of guessing all 50 states… STATES = { 'AL':0, 'AK':0, 'AZ':0, 'AR':0, 'CA':0, 'CO':0, 'CT':0, 'DE':0, 'DC':0, 'FL':0, 'GA':0, 'HI':0, 'ID':0, 'IL':0, 'IN':0, 'IA':0, 'KS':0, 'KY':0, 'LA':0, 'ME':0, 'MD':0, 'MA':0, 'MI':0, 'MN':0, 'MS':0, 'MO':0, 'MT':0, 'NE':0, 'NV':0, 'NH':0, 'NJ':0, 'NM':0, 'NY':0, 'NC':0, 'ND':0, 'OH':0, 'OK':0, 'OR':0, 'PA':0, 'RI':0, 'SC':0, 'SD':0, 'TN':0, 'TX':0, 'UT':0, 'VT':0, 'VA':0, 'WA':0, 'WV':0, 'WI':0, 'WY':0 }

A dictionary challenge… stateDict = { 'AL': 0, … } All US state abbreviations are in this dictionary… key value def stateChallenge( stateDict ): while 0 in stateDict.values(): print(list(stateDict.values()).count(0), \ "states left to guess") guess = input("Name a state: ") if guess not in stateDict: print 'Try again...' elif stateDict[guess] == 0: print 'Yes!' stateDict[guess] += 1 else: print('Already guessed...') print('Phew!') Tell user how many left to guess wasn't a key at all Run stateChallenge in the script… newly guessed key: value was 0 repeated guess