Computationally efficient recording + searching? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Computationally efficient recording + searching? (/thread-9697.html) |
Computationally efficient recording + searching? - IAMK - Apr-24-2018 I have not yet programmed this, so it will be in pseudo code, but I would like to know if my idea is good or there is a better way to do it. I need the most computationally efficient way to do this. Let's assume my script does many computations and then appends strings (e.g. [intint<char>,intint<char>,intint<char>] 2 individual ints and an optional char) to a list. Once the list has been completed, it will be put into a bigger list, if it doesn't already exist. Also, a sort will be performed before putting the list into a bigger list.Note: A set will have on average 3 elements, but can range from 1-15 (made up these numbers, as I don't know the exact math). Examples of biglist and small list(set#) biglist[set1, set2, set3, ..., set1000] set1[31, 53x, 53, 45]Assume x == 0, currently [x] is 31 from the above example of set1 How I will sort my set: 1- Sort [x][0] from smallest to largest.2- Sort [x][1] from smallest to largest.3- If two have the same [x][0] and [x][1] , then one will have an extra char "x" in [x][2] , so the size will be bigger, so I will sort this to be after the one without "x".E.g. set1 would become [31, 45, 53, 53x] How I will search my biglist: for x in biglist if newset[0][0] == biglist[x][0][0] foundflag = true break if foundflag == true append newset to biglist^I need more checks to see if the size of the list and/or all its contents match. New idea: Should I compress all possible strings upfront to ints? Then search the map for the corresponding int before appending to newset , sorting and searching?E.g. [31, 31x, 32, 32x, 33, 33x, 41, 41x, 42, 42x, 43, 43x] would become [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] Then, instead of sorting [x][0] , [x][1] and the size in case of a possible "x" in [x][2] , I simply sort [x] , which is an int?
RE: Computationally efficient recording + searching? - IAMK - Apr-30-2018 Since there have been no suggestions, is it already efficient? |