Python Forum
Newbie to Python - Problem in accessing Dictionaries and List
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie to Python - Problem in accessing Dictionaries and List
#1
Hi there,

I am a newbie into Python and programming in general. While studying python list and dictionaries I stumbled upon a scenario, hear me out please :).

Problem statement:

Scenario 1:
Given a series of numbers list
my_l = [1,3]
gc_i = 1 #i want 1 group
write a function that returns a dictionary like this
my_d = calculate_group (my_l, gc_i);
result
{
0: "1,3"
}
Scenario 2:
Given a series of numbers list
my_l = [1,3]
gc_i = 2 #i want two groups
write a function that returns a dictionary like this
my_d = calculate_group (my_l, gc_i);
result
{
0: "1",
1: "3"
}
Scenario 3:
Given a series of numbers list
my_l = [1,3,2,33,34,36,86,88,99,5]
gc_i = 4 #i want 4 groups
write a function that returns a dictionary like this
my_d = calculate_group (my_l, gc_i);
result
{
0: "1,2,3,5"
1: "33,34,36",
2: "86,88",
3: "99"
}
Now my question is how to divide a list into dictionary based on number of groups provided?

Really appreciate your help.

Thanks

Sam.
Reply
#2
I've moved this to the homework forum, since it looks copy/pasted from a homework assignment.  If that's not the case, that's fine.  Either way, please show your attempt, and we'll help with any issues you may have, but we won't do it for you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unexpected behavior accessing list elements. tonyflute 2 2,274 Apr-09-2021, 02:36 PM
Last Post: tonyflute
  Help with Dictionaries problem alex_0 2 2,381 Mar-22-2021, 08:25 PM
Last Post: alex_0
  Help with Python dictionaries kam_uk 5 2,510 Dec-22-2020, 11:32 PM
Last Post: jefsummers
  Need help comparing totals from list of dictionaries AnOddGirl 1 1,561 Mar-18-2020, 01:17 AM
Last Post: AnOddGirl
  dictionaries and list as values Pippi 6 3,485 Apr-13-2019, 09:05 AM
Last Post: perfringo
  Dictionaries in Python erfanakbari1 1 2,144 Mar-02-2019, 06:40 PM
Last Post: ichabod801
  Newbie to CS and Python, 2 questions johneven 2 2,230 Feb-01-2019, 03:00 AM
Last Post: johneven
  Populating a list with Dictionaries.... SteenRudberg 4 2,683 Sep-26-2018, 11:09 AM
Last Post: SteenRudberg

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020