View Single Post
Old 03-12-2024, 01:33 PM   #10
lomkiri
Zealot
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 136
Karma: 1000102
Join Date: Jul 2021
Device: N/A
Quote:
I actually have a dynamic list of over 200 items
Then I'm not sure it's a good idea to have 200 capturing groups in your regex, maybe it would be better to opt for the dict solution where no capturing group is necessary.

"find : "John|Paul|George|Ringo"
The function (with dict) doesn't change.

You could first create the dict in a json file :
Code:
{
  "John": "Mike",
  "Paul": "Keith",
  "George": "Ronnie",
  "Ringo": "Charlie"
}
and import it into the function.

Then, to create the regex, you could use python to extract the keys from this json file (with dict.keys()) and use the resulting list to create the string "John|Paul|George|Ringo", which you'll use to feed the "find" field

You could also create the json file using another python code, witch will read your text file, transform it in a dict, and write it with json.dump() (after an import json)

Last edited by lomkiri; 03-12-2024 at 03:49 PM.
lomkiri is offline   Reply With Quote