I have a question about the code that I have written.
My table_data is as follows:
table_data = [('|Office|Items|windows', 'furniture/metal/window/frame'),
('|Office|Items|chairs', 'furniture/metal/officeChairs/normal'),
('|Office|Items|chairs_2', 'furniture/metal/officeChairs/normal'),
('|Office|Items|doors|handles', 'furniture/metal/door/handle')]
And when I tried to do the following code, it works to my cause as it sort of ‘grouped’ the same name together such that it will shows only once…
for index, (full_path_name, extra_attr) in enumerate(table_data):
row_position = self.table.rowCount()
self.table.insertRow(row_position)
self.table.setItem(row_position, 0, QtGui.QTableWidgetItem(extra_attr))
Output result is as follows:
Column1 | Column2
furniture/metal/window/frame |
furniture/metal/officeChairs/normal |
furniture/metal/door/handle |
Noticed that furniture/metal/officeChairs/normal
is only shown/populates once…
However, when I start to introduce in something new, so that when a particular radio button is checked…
extra_attr_list = list()
for index, (full_path_name, extra_attr) in enumerate(table_data):
row_position = self.table.rowCount()
self.table.insertRow(row_position)
self.table.setItem(row_position, 0, QtGui.QTableWidgetItem(extra_attr))
extra_attr_list.append(extra_attr)
if self.radio_button.isChecked():
'''
print extra_attr_list
# Output Results :
# set(['furniture/metal/window/frame'])
# set(['furniture/metal/window/frame', 'furniture/metal/officeChairs/normal'])
# set(['furniture/metal/window/frame', 'furniture/metal/officeChairs/normal])
# set(['furniture/metal/window/frame', 'furniture/metal/door/handle', 'furniture/metal/officeChairs/normal'])
'''
for attr in set(extra_attr_list):
self.table.setItem(row_position, 0, QtGui.QTableWidgetItem(attr))
I tried using list()
and set()
so as to filter out the ‘duplicated values’ but still furniture/metal/officeChairs/normal
got displayed twice.
Output results:
Column1 | Column2
furniture/metal/window/frame |
furniture/metal/officeChairs/normal |
furniture/metal/officeChairs/normal |
furniture/metal/door/handle |
What am I missing here? Can anyone advice?