in python

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

in python

Post by answerhappygod »

in python
In Python 1
In Python 1 (27.09 KiB) Viewed 22 times
In Python 2
In Python 2 (27.09 KiB) Viewed 22 times
In Python 3
In Python 3 (31.4 KiB) Viewed 22 times
In Python 4
In Python 4 (27.16 KiB) Viewed 22 times
Define a function named create_words_dictionary words_list) which takes a list of words as a parameter, and creates a dictionary by looping through each element in the list and creating a corresponding key:value item. The "key of each item in the dictionary is the last letter of the word, and the "value" is the word (e.g. key of "o", value of "hello"). Note: You can assume the following: • The list contains unique ending letters. . All words in the parameter list are in lowercase. For example: Test Result words - l'abba', 'bob', 'cutoff, academic', 'aged', 'the', 'dog', 'hello'] words_dict - create_words_dictionary(words) for key in sorted(words_dict) : print(key, words_dict[key]) a abba b bob Cacademic d aged e the fcutoff

Define a function called create_numbers dictionary numbers) which takes a list of integers as a parameter and creates a dictionary by looping through each element in the list. The dictionary is to have three keys: 0, 1, and 2. A key of o represents numbers from 0-9, a key of 1 represents numbers from 10 - 19 and a key of 2 represents numbers from 20 - 29. The value is the frequency count of the range of numbers in the parameter list. Note: you can assume that all numbers are always > = 0 and < 30. For example: Test Result a_dict - create_numbers_dictionary([3, 3, 2, 13, 29, 14, 15, 4, 9)) OS for key in sorted (a_dict): 13 print(key, -_dict[key]) 21 print (type(@_dict) <class dict'> a dict - create_numbers_dictionary ([ 23, 14, 17, 4, 28, 16, 3, 9, 2, 8]) {e: 5, 1:3, 2: 2) print(w_dict) <class 'int'> print (type(a_dict [2]))

Define a function called create numbers dictionary numbers) which takes a list of integers as a parameter and creates a dictionary by looping though each element in the list. The function returns the dictionary that records the frequencies of the numbers 1 to 6 (inclusive) appearing in the parameter list. For example: Result Test 11 23 dict - create numbers_dictionary([3, 2, 2, 3, 2, 4, 5, 4, 11) for key in sorteda dict): print(key, a_dict(key]) print (type(a_dict)) 4 2 51 60 <class 'dict> a_dict = create_numbers_dictionary([3, 4, 1, 4, 2, 6, 3, 4, 2, 1)) (1:2, 2:2, 3:2, 4:3, 5.0, 6: 1) print(a_dict) <class 'int's print (type(a_dict[2]))
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply