擅长:python、mysql、java
<p><code>re.match</code>将只匹配字符串的开头。您可以使用<code>in</code>代替正则表达式:</p>
<pre><code>if exclusion_items in bucket_name:
return False
else:
continue
</code></pre>
<p>也就是说,该函数可以重写为:</p>
<pre><code>def valid_bucket(bucket_name):
bucket_exclusion_list = ['do-not-delete', 'aws-config', 'elasticbeanstalk']
return all(item not in bucket_name for item in bucket_exclusion_list)
</code></pre>