3 ms·
He's using the incorrect datatype for ap_list. This is apprently the collection of AP's already seen, and used with this pattern: ap_list = [] if AP not in
by Luyt 14y ago
He's using the incorrect datatype for ap_list. This is apprently the collection of AP's already seen, and used with this pattern:
ap_list = []
if AP not in ap_list:
ap_list.append(AP)
print AP
It works, but does a linear scan every time. It's better to use a set() in such a case:
ap_seen = set()
if AP not in ap_seen:
ap_seen.add(AP)
print AP
For looking up things, a set (essentially a dict without values) is much quicker than a list. Is this premature optimisation? Perhaps, but using a list for this purpose is also a code smell.
- infoseckid 14y agoNice catch! This may be required as we are comparing against every beacon frame and one could have a large number of them over the air at any time.
- arantius 14y ago> Is this premature optimisation? In this case, I feel that it is not. It's just using the right data set for the job. This is exactly the sort of thing that sets are for.