내 파일은 다음과 같습니다 :파이썬 : 구문 분석 텍스트 파일은
(100)에 의해 2의 매트릭스,
나는 각 열의 각 행의 첫 번째 요소에 대응하는 하나 개의 목록을 목록을 만들 싶습니다전류에 맵핑하고 두 번째 요소는 온도에 맵핑합니다.
아래와 같습니다. 코드를 더 좋아 보이게 만드는 더 좋은 방법은 없을까요?
-12,30
-34,50
-33,89
-900,9
-2,37
-7,17
-8,28
-12,30
-34,50
-33,89
def parse_log(fname):
f = open(fname, "r")
samples = f.readlines()
samples = filter(lambda x: not x.startswith('*'), samples)
print(samples)
current = map(lambda x: -1 * int(x.split(',')[0]), samples)
print(current)
temperature = map(lambda x: int(x.split(',')[1]), samples)
print(temperature)
return (current, temperature)
''lambda ''로'map'과'filter'를 사용하지 마십시오. 이해력을 사용하십시오. – JBernardo