我有以下代码:
class Solution:
def three_sum(self, nums: List[int]) -> List[List[int]]:
nums.sort()
output_set: set = set() #Notice
if len(nums) < 3:
return []
for i in range(len(nums)-2): #at least 2 element left
sub_nums = nums[i+1:]
sub_target = 0 - nums[i]
logging.warning(f"sub_target: {sub_target}")
two_sum_output = self.two_sum(sub_nums, sub_target)
logging.warning(f"two_sum_output: {two_sum_output}")
if two_sum_output != None:
temp = { (nums[i],) + tuple(l) for l in two_sum_output }
output_set.update(temp)
output = [ list(t) for t in output_set] #conver to list
logging.warning(f"final output count: {len(output)}:\n {output}")
return output
我想删除带有logging
,
grep
可以他们
$ grep "logging" twoSum.py
import logging
# logging.disable(level=CRITICAL)
logging.basicConfig(level=logging.debug,
logging.info(f"Start of twoSum Process {os.getpid()}")
# logging.debug(f"{ps.stdout.decode('utf-8')}")
logging.info(f'find: {find} ')
logging.info(f"j: {j}")
如何才能删除它们?
答案1
使用grep -v
并复制到另一个文件
grep -v logging twoSum.py > logging-new
笔记:
- 这将按照您的要求删除包含“logging”的物理行。这可能是一个坏主意,因为PerlDuck 指出
- 如果 grep 的文本中没有空格或奇怪的字符,则不需要“或'。