Write a function countNow(PLACES) in Python, that takes thedictionary, PLACES as an argument and displays the names (inuppercase)of the places whose names are longer than 5 characters.For example, Consider the following dictionaryPLACES={1:"Delhi",2:"London",3:"Paris",4:"NewYork",5:"Doha"}The output should be:LONDONNEW YORK
Question
Write a function countNow(PLACES) in Python, that takes thedictionary, PLACES as an argument and displays the names (inuppercase)of the places whose names are longer than 5 characters.For example, Consider the following dictionaryPLACES={1:"Delhi",2:"London",3:"Paris",4:"NewYork",5:"Doha"}The output should be:LONDONNEW YORK
Solution
Sure, here is the Python function that you asked for:
def countNow(PLACES):
for place in PLACES.values():
if len(place) > 5:
print(place.upper())
This function iterates over the values in the PLACES dictionary. For each place, it checks if the length of the place's name is greater than 5. If it is, it prints the name of the place in uppercase.
Similar Questions
Question 1: Consider the following list of countries and their capital cities:country_capitals = ["USA: Washington D.C.", "France: Paris", "India: New Delhi", "Russia: Moscow", "China: Beijing"]Create a dictionary using a dictionary comprehension where the country name is the key and the capital city is the value.
Question 3: Given a list of cities, create a new list where each element is a tuple containing the city name and its length.cities = ["New York", "London", "Tokyo", "Paris", "Sydney"]
Question 2: For a given list of strings, please create a new list where each element is the uppercase version of the first letter of a string with a length greater than or equal to 5 in the original list.words = ["apple", "banana", "orange", "mango", "kiwi", "pear"]
A sentence about the native place is given first as input(give without any space). Then enter the name of your native place. Then implement the following steps:(i)Find the frequency of occurrence of each character. Find the highest frequency character and reprint the sentence replacing that character by ‘@’.(ii) sort the alphabets and print.(iii)In the name of the native place, if the string length is odd number, then replace the middle char as “C” else if the string length is even then replace the middle two char as “E” use replace method.Ex:IlovemynativeplaceChennai
A sentence about the native place is given first as input(give without any space). Then enter the name of your native place. Then implement the following steps:(i)Find the frequency of occurrence of each character. Find the highest frequency character and reprint the sentence replacing that character by ‘@’.(ii) sort the alphabets and print.(iii)In the name of the native place, if the string length is odd number, then replace the middle char as “C” else if the string length is even then replace the middle two char as “E” use replace method.Ex:IlovemynativeplaceChennaiOutput: Ilov@mynativ@plac@aaceeeiillmnoptvvyCheCnai
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.