Apr-20-2024, 02:23 PM
(This post was last modified: Apr-20-2024, 03:28 PM by deanhystad.)
Here is the code. The data comes from a file with lines of 15 pieces of text separated by a space. The first piece of text in each line will become the 'key' and a temporary list is made of other pieces of text and that list is to be the 'value' for the respective 'key'. Each time through, the new key is added, but, after all the data is processed, every key ends up with the same list as the value.
for new_line in data: new_line = new_line.strip() print(f'\n{new_line} : Line Length = {len(new_line)}') # read in the rd info / split on whitespace rd_info = list(new_line.split()) print(rd_info) # create dictionary temp_list.clear() rd_name = rd_info[0] rd_age = int(rd_info[3]) rd_yr = int(rd_info[6]) rd_yr_left = rd_yr rd_wt = int(rd_info[13]) rd_wt_left = rd_wt rd_fg = 0 rd_stp = 0 temp_list.append(','.join([str(rd_age), str(rd_yr), str(rd_yr_left), str(rd_wt), str(rd_wt_left), str(rd_fg), str(rd_stp)])) print(f'Temp List: {temp_list}') rd_dict[rd_name] = temp_list print(rd_dict)
deanhystad write Apr-20-2024, 03:28 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.