我想从字符串中提取某种类型的变量名(不允许使用数字、_等),不需要任何导入(仅限于纯Python),并且尽可能短(即使它不可读).
我该怎么做呢?
示例:
"asd123*456qwe_h"->;[asd,qwe,h].
(不允许使用‘a’、‘qw’等)
我想从字符串中提取某种类型的变量名(不允许使用数字、_等),不需要任何导入(仅限于纯Python),并且尽可能短(即使它不可读).
我该怎么做呢?
示例:
"asd123*456qwe_h"->;[asd,qwe,h].
(不允许使用‘a’、‘qw’等)
仅限内置:
s = 'asd123*456qwe_h'
print(s.translate(str.maketrans({k: ' ' for k in s if not k.isalpha()})).split())
Output:个
['asd', 'qwe', 'h']