-
-
Save LizaPiya/5574df58f0eef1d7bd9ed49c44464855 to your computer and use it in GitHub Desktop.
11.8. Accumulating the Best Key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 1. Create a dictionary called d that keeps track of all the characters in the string placement and notes how many times each character was seen. Then, find the key with the lowest value in this dictionary and assign that key to min_value. | |
| placement = "Beaches are cool places to visit in spring however the Mackinaw Bridge is near. Most people visit Mackinaw later since the island is a cool place to explore." | |
| d={} | |
| for i in placement: | |
| if i not in d: | |
| d[i]=0 | |
| d[i]=d[i]+1 | |
| print (d) | |
| ks=list(d.keys()) | |
| print (ks) | |
| min_value=ks[0] | |
| for key in ks: | |
| if d[key]< d[min_value]: | |
| min_value=key | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Create a dictionary called lett_d that keeps track of all of the characters in the string product and notes how many times each character was seen. Then, find the key with the highest value in this dictionary and assign that key to max_value. | |
| product = "iphone and android phones" | |
| lett_d={} | |
| for i in product: | |
| if i not in lett_d: | |
| lett_d[i]=0 #Initializing the dictionary | |
| lett_d[i]=lett_d[i]+1 | |
| print (lett_d) | |
| ks=list(lett_d.keys()) | |
| print (ks) | |
| max_value=ks[0] | |
| for key in ks: | |
| if lett_d[key] > lett_d[max_value]: | |
| max_value=key | |
hadrocodium
commented
Apr 5, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment