Получив этот список ['customer_id', 'action_id']
, вы можете использовать findall
, используя ^[^_]+
regex, чтобы извлечь часть перед _id
.Попробуйте этот код Python,
import re
subject = re.compile(r'.*_id')
dict = {'name': 'Robert', 'customer_id': 2, 'action_id': 5}
results = list(filter(subject.match, dict))
results = [''.join(re.findall(r'^[^_]+',s)) for s in results]
print(results)
Prints,
['customer', 'action']