作为这个原始问题的后续: Python: Stripping elements of a string array based on the first character of each element
我想知道是否可以扩展此 if 语句:
with open(bom_filename, 'r') as my_file:
file_array = [word.strip() for word in my_file if word.startswith("/")]
包括和第二个条件:
with open(bom_filename, 'r') as my_file:
file_array = [word.strip() for word in my_file if (word.startswith("/")) & not(word.endswith("/"))]
这会产生语法错误,但我希望可以使用一些替代语法!