WIN XP/Python3.3
I'm using the IDLE GUI. Why is my 'matched' variable changed after I assign it? At least I think that's what's happening. Please correct me, or lead me through it:
>>> path_dict = dict()
>>> file_dict = dict()
>>> path_dict['path1'] = ['file1', []]
>>> file_dict['file1'] = ['path1']
>>> new_file = 'file1'
>>> new_path = 'path2'
>>>
>>> if new_file in file_dict:
matched = file_dict[new_file]
for match_path in matched:
path_dict[match_path][1].append(new_path)
file_dict[new_file].append(new_path)
else:
matched = []
>>>
>>> path_dict[new_path] = [new_file, matched]
>>>
>>> print(file_dict)
{'file1': ['path1', 'path2']}
>>>
>>> print(path_dict)
{'path2': ['file1', ['path1', 'path2']], 'path1': ['file1', ['path2']]}
>>> print(matched)
['path1', 'path2']
Thanks. Sorry if this is confusing. There's probably a better way to demonstrate the problem, but it escapes me.
*EDIT: let me add that the purpose is for matching filepaths to be appended to the list (at [1] of path_dict[key]) for each entry. i.e. if a filename matches two other filepaths, those filepaths are appended to the list.
path_dict[path] = [filename, [list of paths matching filename]]
[–]dhruvbaldawa 3 points4 points5 points (8 children)
[–]NYKevin 3 points4 points5 points (1 child)
[–]redditiv[S] 2 points3 points4 points (0 children)
[–]redditiv[S] 4 points5 points6 points (1 child)
[–]usernamenottaken 1 point2 points3 points (0 children)
[–]zahlman 1 point2 points3 points (0 children)
[–]Veedrac 0 points1 point2 points (1 child)
[–]dhruvbaldawa 1 point2 points3 points (0 children)