Python Forum
From string parameter to a dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
From string parameter to a dictionary
#5
I don't think that's what readlines is giving you. I expect it is giving you ['participant_id;lesson_number;rating', '103;1;2', '103;6;2']. This is a list of strings. This is what you need to do: initialize an empty dictionary. Loop through each string the realines list (except the first one). For each one, pull out the student id, lesson number, and rating; convert them to integers; if the student id isn't in the dictionary add it with seven NAs, then put the rating in for the correct lesson.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: From string parameter to a dictionary - by ichabod801 - Oct-12-2019, 06:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  to find in dictionary given parameter 'name' and to output position Liki 10 1,363 Oct-08-2023, 06:38 AM
Last Post: Pedroski55
  How to change part of the value string in Python Dictionary? sbabu 11 3,919 Feb-12-2020, 02:25 AM
Last Post: sbabu

Forum Jump:

User Panel Messages

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