Python Forum

Full Version: Find field name from all possible values
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all!

Here I am new my first post :)

I have started learning python.

I have question is there better solution, than this:
ols = dict(
  clicks='Hits,Clicks,clicks' # define all possible clicks alternatives 
)

results = dict(
  Hits=2
)

# find the field name by how to search in the results
clicks_col_name = [i for i in results if any(i == x for x in cols['clicks'].split(","))]
clicks = results[clicks_col_name[0]] if len(clicks_col_name) > 0 else None

print (clicks)
How about starting off by describing what it is you are trying to do?