0


I want to write my own voice assistant in python.
The conversion from speech to text is solved, but now I want to compare strings efficiently.

Thereby the code should be written as generic as possible.
Lets say I want to greet a guest with his name. I am going to say: "Hey Jarvis, greet my friend Lars." but the code for it should not be hard coded on lars and other names but on every name. I think this would be possible with regular expressions, but here comes the clue.

As I expect my software to become relatively larger,
I may need to compare hundreds of generic regular expressions.
This is too much time for a system which should ease my life (not make me spend more time).


Do you have any advice for me?

I thought about using sets, but I do not know how to integrate regular expression in them.

Red
  • 26,798
  • 7
  • 36
  • 58

1 Answers1

1

I thought about using sets, but I do not know how to integrate regular expression in them.

Here is how:

import re

s = {'Today','is','my','lucky','day,','because','today','is','Thanksgiving','day!'}
s = ' '.join(s)
print(re.findall(r'[A-Z]',s)) # Find all the capital letters in this example

Output:

['T', 'T']
Red
  • 26,798
  • 7
  • 36
  • 58