Since, it is possible that the new device can be store at any dictionary index because of alphabetical order. But I am quite confused if the scenario is like this: I tried comparing their keys and values I managed to do that. I want to compare if the two dictionaries are equal. Say for an instance, I have Dict1 that holds values of the ListView and I have Dict2 which will hold the values of the listView and the new detected device. By the way, the values displayed in the ListView are alose stored in the Dictionary. So if the thread detected the new device, I store it to another Dictionary. I displayed two similar devices since the PC detected two similar devices.īut my problem now is that, my program run a thread that will automatically detect a new device connected to the PC. So, for the example above, I want to display the like this: I want to display only the device name exclusing their interfaces. Now, I want to display the devices' name to the listView and I want it to be sorted. Key-value is provided in the dictionary to make it more optimized. The index may vary according to the number of similar device connected to the PC. Dictionary in Python on the other hand is an unordered collection of data values, used to store data values like a map, which unlike other Data Types that hold only single value as an element, Dictionary holds key:value pair. So, given the example above, device1 and device2 are just similar device having the same device name but their interfaces have different index. they only differ in theie interface index. The program can detect similar device name. each devices may have different interfaces. I have a listView that will display a list of devices. Im just kinda confused with what I have encountered. There are several ways you could go about this, that's just one suggestion. Perhaps when you detect differences, you can trigger an event from your processing thread to your GUI thread to have your ListView update? If you wanted to compare values you could change the code to do that.Īs for comparing them without having an impact on the process, you'll probably want to do the compare in another thread, and make sure you use the lock statement to ensure you're not reading and writing to the dictionaries at the same time. You might have to do another pass if you also want the items that dictionary1 has but dictionary2 doesn't have.Īlso this is comparing keys, as a Dictionary object is essentially a list of KeyValuePair objects. That should populate newItems with all the keys that dictionary2 has but dictionary1 doesn't have.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |