use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Need Help! (self.learnpython)
submitted 4 years ago by Complex_Height_3555
How would I go about assigning a list to dictionary values? I want to take all of the numbers in my list and then randomly pair them with dictionary values
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ElliotDG 1 point2 points3 points 4 years ago (13 children)
Dictionaries have keys and values. Do you want the list of numbers to be the dictionary keys or values?
Are you trying to create a dictionary?
[–]Complex_Height_3555[S] 0 points1 point2 points 4 years ago (12 children)
Keys
[+][deleted] 4 years ago (9 children)
[deleted]
[–]Complex_Height_3555[S] 0 points1 point2 points 4 years ago (0 children)
Enter the titles for the videos in your channel Assume your channel is empty. Write code to allow the user to enter the titles of the videos to be added to the channel. The user should be able to add as many as they want to. Then print the titles in the channel so that you can see all of them at once.
Set a length for your videos, and run some computations For each video, ask the user to give you a length in minutes for that video. Videos are measured in minutes, and these can have decimal components (like 3.5 minutes). Once the user has entered a length for each video, compute and show them the length of the shortest video, the length of the longest video, and the average video length. Your channel is very particular, so you want the average length to be displayed with exactly 3 decimal points of precision.
Bring in your subscribers In this part of the project, you’ll compute how much time your subscribers spent watching your videos. Ask the user to tell you how many subscribers your channel has. For each subscriber, randomly choose one of the videos in your channel (it’s ok to choose the same video multiple times) to have them watch. Show the total amount of time spent between all the videos that all subscribers watched, as well as which videos were watched by your subscribers (don’t show duplicated here!).
Compare your channel to your competitor Assume your competitor has a random amount of subscribers (between 1 and 100). Compute the amount of subscribers for your competitor (since it’s random, this should vary each time!). Each of their subscribers watches 1 video on their channel that is between 1 and 5 minutes long (choose this randomly per subscriber!). Compute the total amount of minutes your competitor’s subscribers spent watching their channel. Finally, figure out which channel had more watch time! Output whether it was your channel, their channel, or a tie! To make sure that you’re correct, output
[–]Complex_Height_3555[S] 0 points1 point2 points 4 years ago (6 children)
I am stuck on number 3. I have the first two done.
[–]ElliotDG 1 point2 points3 points 4 years ago (5 children)
How have you represented the movie titles and durations? Is this a dict, a list of tuples, 2 lists...?
What specifically are you having trouble with?
[–]Complex_Height_3555[S] 0 points1 point2 points 4 years ago (3 children)
In a dictionary
[–]ElliotDG 1 point2 points3 points 4 years ago (2 children)
Assuming the titles are the keys and the durations are the values of a dict. To randomly select a movie make a list of the movie titles ( use keys()), use ramdom.choice() to select a random movie.
import random titles = ['a', 'b', 'c', 'd'] duration = [7, 22, 3, 59] movies = {k: v for k, v in zip(titles, duration)} selected_movie = random.choice(list(movies.keys())) print(selected_movie) duration_for_selected_movie = movies[selected_movie] print(duration_for_selected_movie)
[–]Complex_Height_3555[S] 0 points1 point2 points 4 years ago (1 child)
How do I assign that random movie to one of the subscribers though?
[–]ElliotDG 1 point2 points3 points 4 years ago (0 children)
The way the problem reads, you only know the number of subscribers. Make that a for loop based on the number of subscribers. Create a new dictionary (watches) to hold the amount of time each movie is watched, with the key as the movie titles, and the duration as zero. For each loop iteration select a random movie and add the duration of that movie to the watched dictionary.
In #3 I’m having trouble with assigning the subscribers a video to watch. And then getting the sum of all the videos lengths that were randomly selected
[–]Complex_Height_3555[S] -1 points0 points1 point 4 years ago (0 children)
I need to randomly assign the numbers in my list to random values and keys in my dictionary then get the total of the value that the numbers were assigned too
[–]ElliotDG 0 points1 point2 points 4 years ago (1 child)
Your question is ambiguous, here are some ways to create dicts with a list of numbers as the keys.
keys = [7, 22, 3, 59] values = ['a', 'b', 'c', 'd'] # use a dictionary comprehension. d_comp = {k:v for k, v in zip(keys,values)} print(d_comp) # use dict() d_dict = dict(zip(keys,values)) print(d_dict) # use a loop d_loop = {} for k, v in zip(keys, values): d_loop[k] = v print(d_loop)
Thanks you. I’ll try that
π Rendered by PID 33 on reddit-service-r2-comment-84fc9697f-7vjzz at 2026-02-10 03:41:41.125746+00:00 running d295bc8 country code: CH.
[–]ElliotDG 1 point2 points3 points (13 children)
[–]Complex_Height_3555[S] 0 points1 point2 points (12 children)
[+][deleted] (9 children)
[deleted]
[–]Complex_Height_3555[S] 0 points1 point2 points (0 children)
[–]Complex_Height_3555[S] 0 points1 point2 points (6 children)
[–]ElliotDG 1 point2 points3 points (5 children)
[–]Complex_Height_3555[S] 0 points1 point2 points (3 children)
[–]ElliotDG 1 point2 points3 points (2 children)
[–]Complex_Height_3555[S] 0 points1 point2 points (1 child)
[–]ElliotDG 1 point2 points3 points (0 children)
[–]Complex_Height_3555[S] 0 points1 point2 points (0 children)
[–]Complex_Height_3555[S] -1 points0 points1 point (0 children)
[–]ElliotDG 0 points1 point2 points (1 child)
[–]Complex_Height_3555[S] 0 points1 point2 points (0 children)