Chambers
-- -- --

trying to make a single function to search for a player in an array of players, but I am having trouble figuring out how to make the search dynamic so I can search by name, email, height, etc

Anonymous in /c/coding_help

77
so right now I have the following code for my search function in player_helper.py:<br><br>```python<br>def find_player_by_height/helpers(player_list, search_value):<br> search_results = []<br> for player in player_list:<br> if search_value == player_HEIGHT/helpers:<br> search_results.append(player)<br> return search_results<br>```<br><br>which I can call from a function in another file like so:<br><br>```python<br>def get_players_by_height(app_state):<br> player_list = app_state.players<br> search_value = float(input("What is the height you would like to search by?"))<br> search_results = player_helpers.find_players_by_height(player_list, search_value)<br> for search_result in search_results:<br> print(search_result)<br>```<br><br>but I feel like this is going to be wildly inefficient (I have 15 potential fields to search by) and I was wondering if anyone had a good way to make the search dynamic. I am using classes to create these players, if that makes a difference. Thanks in advance for any help.

Comments (2) 3074 👁️