KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am receiving the error TypeError: 'filter' object is not subscriptable When trying to run the following block of code bonds_unique = {} for bond in bonds_new: if bond[0] < 0: ghost_atom = -(bond[0]) - 1 bond_index = 0 elif bond[1] < 0: ghost_atom = -(bond[1]) - 1 bond_index = 1 else: bonds_unique[repr(bond)] = bond continue if sheet[ghost_atom][1] > r_length or sheet[ghost_atom][1] < 0: ghost_x = sheet[ghost_atom][0] ghost_y = sheet[ghost_atom][1] % r_length image = filter(lambda i: abs(i[0] - ghost_x) < 1e-2 and abs(i[1] - ghost_y) < 1e-2, sheet) bond[bond_index] = old_to_new[sheet.index(image[0]) + 1 ] bond.sort() #print >> stderr, ghost_atom +1, bond[bond_index], image bonds_unique[repr(bond)] = bond # Removing duplicate bonds bonds_unique = sorted(bonds_unique.values()) And sheet_new = [] bonds_new = [] old_to_new = {} sheet=[] bonds=[] The error occurs at the line bond[bond_index] = old_to_new[sheet.index(image[0]) + 1 ] I am fairly new to Python and do not fully understand dictionaries. Am I trying to use a dictionary in a way in which it should not be used, or should I be using a dictionary where I am not using it? I am using Python IDLE 3.3.1 on Windows 7 64-bit.
Tags (comma-separated)
Save Edits
Cancel