Python 这里如何使用Ignore case?

Python 这里如何使用Ignore case?,python,regex,dictionary,Python,Regex,Dictionary,我的代码如下: d={ 'h' : 'hhh' , 'l' : 'lll'} enpattern = re.compile(r'(.)\1?') str='HeLlo' result = [x.group() for x in enpattern.finditer(str)] data=''.join(map(lambda x:D.get(x,x),result)) print data 这段代码从字符串中提取每个字符,并将其与字典中的键进行比较,然后给出相应的值。但是

我的代码如下:

  d={ 'h' : 'hhh' , 'l' : 'lll'}
  enpattern = re.compile(r'(.)\1?')
  str='HeLlo'
  result = [x.group() for x in enpattern.finditer(str)]
  data=''.join(map(lambda x:D.get(x,x),result))
  print data

这段代码从字符串中提取每个字符,并将其与字典中的键进行比较,然后给出相应的值。但是在这里,当使用finditer()方法时,我怎么能忽略大小写敏感度呢?

根据您的评论,您希望得到
hhhelllllo
,所以这就是您所期望的

result = [m.lower() for x in enpattern.finditer(my_string) for m in x.group()]
data   = ''.join(map(lambda x: d.get(x, x),result))
不要将变量命名为
str
,因为这会隐藏内置函数

注意:您根本不需要正则表达式来获得输出。这是一条简单的单行线

print ''.join(map(lambda x: d.get(x, x), my_string.lower()))
# hhhellllllo

我试过了,但没用。我得到的输出是-hhheLlo@NBA预期的输出是什么?hhhellllllo,re.compile(r'(?