Posted March 16, 2021 Hi there, I am building a system for storage which will most likely have a raspberry pi as the host. How would I make it so I could easily search in all “boxes” and then see if they have the item that I am looking for. I would be using Python 3 #CODE EXAMPLE THINGY# Box1 [car,dog,sheep] Box2 [rock,cat,sheep] Input for search “sheep” Then searches all boxes I have made to see if it that has sheep in them If it has them then it goes: OUTPUT: Sheep in box 1 and 2 Else goes item unavailable. Input for search “car” Searches all boxes I have made to see if it has car in them* If it has them then it goes: OUTPUT: Car in box 1 This is an example and colours, led and items in box would be different. I don’t mind just needing to use the terminal in order to find an item that is required. If you have any questions feel free to ask and I will try and get back to you ASAP. I am not asking for someone to code the entire thing I am just asking if anyone knows any systems that have been made like this and if there is any ideas on what systems I should use. If you want to reach me privately my discord is Spoiled_Kitten#4911 Thanks, Blake McCullough UwU Link to comment https://linustechtips.com/topic/1315706-python-3-search-in-multiple-array-style-things-to-find-item/ Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 16, 2021 Can we get more context? Python can do this, you just have to point it to where to look Community Standards || Tech News Posting Guidelines ---======================================================================--- CPU: R5 9600X || GPU: RX 9070 XT|| Memory: 32GB || Cooler: Peerless Assassin || PSU: RM850e|| Case: Lian Li A3 Link to comment https://linustechtips.com/topic/1315706-python-3-search-in-multiple-array-style-things-to-find-item/#findComment-14564167 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 16, 2021 I imagine something like this item = input() output = [] for i in boxes: if item in i: output.append(i) print(output) Link to comment https://linustechtips.com/topic/1315706-python-3-search-in-multiple-array-style-things-to-find-item/#findComment-14564583 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 17, 2021 Tbf this sounds like it would be better put in a database of some sort, it'll be far faster then looping over everything to see if an item is in an array. ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´ Link to comment https://linustechtips.com/topic/1315706-python-3-search-in-multiple-array-style-things-to-find-item/#findComment-14567535 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 17, 2021 The simplest solution would be just looping over your lists: if len([item for item in box1 if item == search]) > 0: print(f"{search} is in box1") Then again for the other boxes. However, this will get slow real fast if you're storing a large amount of items. You can speed this up by sorting the data and using other search algorithms. Binary search is O(log(n)) as apposed to O(n) in this linear search. Another approach would which has been stated is using a DB. At least that also takes care of storing the boxes data when your program isn't running. Personally (because I like them) I'd use flask or django. Serve a simple web app that can search a DB and provide other functionality with the added bonus of it being available on your local network. You can get something like this set-up in no time at all. Link to comment https://linustechtips.com/topic/1315706-python-3-search-in-multiple-array-style-things-to-find-item/#findComment-14567628 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 19, 2021 Author On 3/17/2021 at 6:20 PM, vorticalbox said: Tbf this sounds like it would be better put in a database of some sort, it'll be far faster then looping over everything to see if an item is in an array. yeah i ended up doing it i can share if anyone is interested UwU Link to comment https://linustechtips.com/topic/1315706-python-3-search-in-multiple-array-style-things-to-find-item/#findComment-14572478 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now