Question

In: Computer Science

Python programming question: Suppose i have a list like: ['a:10', 'b:9', 'c:8', 'd:7', 'e:6', 'f:5', 'g:4',...

Python programming question:

Suppose i have a list like:

['a:10', 'b:9', 'c:8', 'd:7', 'e:6', 'f:5', 'g:4', 'h:3', 'i:2', 'j:1', 'k:0']

How do i trans form this into a dictionary or something i can plot a graph with using these keys and value pairs?

thanks.

Solutions

Expert Solution

If you have any queries please comment in the comments section I will surely help you out and if you found this solution to be helpful kindly upvote.

Solution :

Code:

import matplotlib.pyplot as plt
# transform function to transform list into a dictionary
def transform(li):
# declare an empty list
di={}
# iterate over the list
for item in li:
# split the item on the basis of :
items=item.split(':')
# make a key-value pair in the dictionary
di[items[0]]=items[1]
# return the dictionary
return di
# function to plot a bar graph
def plot(di):
# plot a bar graph using keys and values of the dictionary
plt.bar(di.keys(),di.values())
  
# declare the list
li = ['a:10', 'b:9', 'c:8', 'd:7', 'e:6', 'f:5', 'g:4', 'h:3', 'i:2', 'j:1', 'k:0']
# call the transform function to transform the list to a dictionary
di=transform(li)
# print the dictionary
print(di)
# call the plot function to plot the values
plot(di)

Output :


Related Solutions

You are given the independent jobs A(5), B(7), C(10), D(12), E(6), F(4), G(3). (a) Using the...
You are given the independent jobs A(5), B(7), C(10), D(12), E(6), F(4), G(3). (a) Using the alphabetical order priority list above, if the jobs are scheduled on 3 processors, what is the completion time? (b) If the decreasing time algorithm is used to schedule the jobs on 3 processors, what is the completion time? (c) If the decreasing time algorithm is used to schedule the jobs on 3 processors, which is the second job scheduled on processor 1? A b...
a = [3, -4, 7] b = [-6, 9, 8] c = [4, 0, 8] d...
a = [3, -4, 7] b = [-6, 9, 8] c = [4, 0, 8] d =[7, 1, 7] e = [3, -5, 2, 1] f =[5, -7, -3, 6] g = [3, -4, 4, 3] P = Projection of ex. C = |g|(gf/gf) C = gf/|f| ex. P g --> f = Cgf = C(gf/f) (1/|f|) (f) =( gf/ff)(f) Find a. Pg --> f b. Pa --> 3b + e Find (cross multiply) a. ||a X b|| b. ||g...
If there are 7 total notes C, D, E, F, G, A, and B and if...
If there are 7 total notes C, D, E, F, G, A, and B and if a five-note melody is selected at random (so that all melodies counted in part (a) are equally likely to be chosen), what is the probability that the melody will include exactly two “A” notes, but no other repeated notes? (A few allowable examples: AACEG, ACAEG, DFACA, EAABC, etc.)
3, 7, 8, 5, 6, 4, 9, 10, 7, 8, 6, 5 Using the previous question...
3, 7, 8, 5, 6, 4, 9, 10, 7, 8, 6, 5 Using the previous question 's scores, If three points were added to every score in this distribution, what would be the new mean? If three points were added to every score in this distribution, what would be the new standard deviation. Remember, you have already calculated population standard deviation in a previous problem. This problem requires two answers.
A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5]...
A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5] D = [1, -9, 5, -3] E = [3, 3, -1] Uz = 1/|z| ^z d(X,Y) = (Rθ) d = diameter R = Radius θ = Theta Find a. Uc b. d (D, C) c. Let P = B + 3E, UP = d. A x B e. 3B x E f. C x D
Seven people (A,B,C,D,E, F, and G) are seated in a row. Suppose A,B, and C are...
Seven people (A,B,C,D,E, F, and G) are seated in a row. Suppose A,B, and C are freshmen, D and E are sophomores and F and G are juniors. How many arrangements are possible if: (a) D and F must sit together? (b) A and C must not sit together? (c) All freshmen must sit together? (d) All freshmen must sit together, all sophomores must sit together, and all juniors must sit together? (e) Exactly two people sit between A and...
In how many ways can 7 people { A, B, C, D, E, F, G }...
In how many ways can 7 people { A, B, C, D, E, F, G } be seated at a round table if (a) A and B must not sit next to each other; (b) C, D, and E must sit together (i.e., no other person can sit between any of these three)? (c) A and B must sit together, but neither can be seated next to C or D. Consider each of these separately. For (c) you may NOT...
Find the value of a : b : c : d, if a : b = 2 : 3, b : c = 4 : 5 and c : d = 6 : 7.
Find the value of a : b : c : d, if a : b = 2 : 3, b : c = 4 : 5 and c : d = 6 : 7.
(a) (f ∘ g)(3) (b) g(f(2)) (c) g(f(5)) (d) (f ∘ g)(−3) (e) (g ∘ f)(−1) (f) f(g(−1))
(a)    (f ∘ g)(3) (b)    g(f(2)) (c)    g(f(5)) (d)    (f ∘ g)(−3) (e)    (g ∘ f)(−1) (f)    f(g(−1))  
Exhibit 25-3 Firms Market Share A 7% B 12% C 3% D 9% E 10% F...
Exhibit 25-3 Firms Market Share A 7% B 12% C 3% D 9% E 10% F 20% G 6% H 6% I 14% J 5% K 5% L 3% ​ Refer to Exhibit 25-3. The four-firm concentration ratio for this industry is a. 46 percent. b. 49 percent. c. 56 percent. d. 44 percent. e. This cannot be determined without further information. Refer to Exhibit 25-3. The Herfindahl Index for this industry is currently a. 10,000. b. 840. c. 1,980....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT