Question:
Adding dict in Python?
•Carrot Plush•
2009-11-30 01:11:49 UTC
Forgive me if this is a repeat question, I seem to be having problems with the website.

Anyway, I have a homework question:
Assume there is a variable, album_artists , that is associated with a dictionary that maps albums to performing artists. Write a statement that inserts the key/value pair: "Live It Out" / "Metric" .

my solution is very simple:

album_artists["live it out"] = "Metric"

However, the program keeps telling me the answer is wrong, and so I have no idea how to solve this, solutions?
Five answers:
2016-03-01 00:52:11 UTC
Take the list 4 5 88 5 4 9 8 9 Now, make it into pairs, with the index recorded as the second element: (4 0) (5 1) (88 2) (5 3) (4 4) (9 5) (8 6) (9 7) Next, sort by the first element of each pair, yielding: (4 4) (4 0) (5 3) (5 1) (8 6) (9 7) (9 5) (88 2) Scan the list, removing the duplicates. They are now TOGETHER, because they have been sorted together, so you only need to look at the first two elements. Always take the element with the lowest index number. After this step: (4 0) (5 1) (8 6) (9 5) (88 2) Sort by the SECOND element of each pair (the added index element): (4 0) (5 1) (88 2) (9 5) (8 6) Display each first element: 4 5 88 9 8 ================================== Memory usage: number elements * 2, or O(n) Time usage: sort is O(n log n), two sorts and two scans of n elements:, or O(n log n)
2014-10-24 12:14:00 UTC
Discover now the best sport betting system: http://sport-betting-tips.checkhere.info



Too many people think of sports betting as just something they do in their past time. However, many people can see the potential that exists if you manage to have the right sports betting strategy and correct approach to betting in general. Are you sick of losing? Interested in finding out how to turn your luck around? Do you want to know which sports betting strategies stand to help you make the most from your betting?



Any good strategy should allow you to place bets based on a systematic method. Of course there is always a random element or so called luck involved, but betting is all about stacking the odds in your favor. There should be no guess work involved or bets placed based on gut feelings. Betting is a business and it should be treated like one. Any money you use for betting needs to be separate from money you use for your daily life or anything else. How can you possibly expect to follow a strategy with money that was originally set aside to pay next week's rent with? You can't. This will help you to focus on the task of betting and remove any emotional strings attached to the money.



So what makes a good strategy or what should you look for in a strategy before you decide to implement it? Any good strategy needs to have a positive expectancy. This means that in the long run you will win. The hit rate of the strategy needs to be above 50% for you to be able to profit in the long run. An ideal win rate should be between 60 to 70%, because you will need to cover the fees and other expensive associated with betting. Is it feasible to expect you'll be able to find a system that has a 100% win rate? No, it isn't. The best you can do is find a system that has a positive expectancy and stick with it. In the long run you will make more money than you can possibly lose.



Keep whatever information and news you have about the teams as up to date as possible. Any changes in the teams makeup or factors that affect how the players play will great affect the potential outcome of a match. Make sure that you are constantly up to date on every aspect that affects the potential outcome of a match. Information is the key to winning at sports betting.
2016-10-07 03:13:29 UTC
Metric Live It Out
Lie Ryan
2009-11-30 01:39:27 UTC
using dict.update to insert a single item creates unnecessary dict that just got dumped away immediately. The correct way, is as you have stated:



album_artists["Live It Out"] = "Metric"



perhaps you should pay attention to the capitalization.

album_artists["live it out"] = "Metric"

is different from

album_artists["Live It Out"] = "Metric"
2009-11-30 01:19:11 UTC
Technically your solution is perfectly valid. You could also use the "update" method, e.g.:



album_artists.update( {"live it out": "metric} )


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...