-2

For a program that takes information from the network I would like to display it in a table to make selections (calculate average, stdev ect.). I created a list of lists and I am trying to populate it into a treeview table. The populating works, but I get 3 duplicates of every row and the final result as found in the nested list shows 7 duplicates (while my list of lists only shows 1 result per line).

I've been struggling for some time to remove the duplicates and checked the suggestions here.

fullResults = [['a', '1', '2'], ['b', '3', '4'], ['c', '5', '6']]
 
def displayInfo():
    for results in fullResults:
        for result in results:
            for value in result:
                tree.insert('', 'end', values=result)

Can you please point me to some direction as the suggested tree.delete(*tree.get_children()) didn't work for me?

EDIT: after removing the last for loop, I managed to get the issue resolved and data is formatted nicely into the table.

1

2 Answers 2

1

I think that you should not use the loop " for value in result" because you are inserting "values= result" in the last command i.e. "tree.insert". Using for in loop, you are iterating over all the elements in iterable i.e. result. But you are inserting in the treeview- the value that the variable "result" holds. So it means by using the loop you are inserting in the treeview table-n number of times-the value that the variable "result" stores . Here, 'n' is the length of iterable "result".

Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

Can use 'set' instead of list to avoid duplications automatically

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.