ответвлено от main/python-labs
test: done
Этот коммит содержится в:
0
TEMA7/test.md
Обычный файл
0
TEMA7/test.md
Обычный файл
39
TEMA7/test.py
Обычный файл
39
TEMA7/test.py
Обычный файл
@@ -0,0 +1,39 @@
|
||||
def read_file_to_list(filename):
|
||||
result = []
|
||||
try:
|
||||
f = open(filename, 'r', encoding='utf-8')
|
||||
lines = f.readlines()
|
||||
f.close()
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if line == '':
|
||||
continue
|
||||
elements = line.split(',')
|
||||
row = []
|
||||
for elem in elements:
|
||||
elem = elem.strip()
|
||||
if elem.isdigit() or (elem.startswith('-') and elem[1:].isdigit()):
|
||||
row.append(int(elem))
|
||||
else:
|
||||
try:
|
||||
if '.' in elem:
|
||||
parts = elem.split('.')
|
||||
if len(parts) == 2:
|
||||
if (parts[0].isdigit() or (parts[0].startswith('-') and parts[0][1:].isdigit())) and parts[1].isdigit():
|
||||
row.append(float(elem))
|
||||
else:
|
||||
row.append(elem)
|
||||
else:
|
||||
row.append(elem)
|
||||
else:
|
||||
row.append(elem)
|
||||
except:
|
||||
row.append(elem)
|
||||
|
||||
result.append(row)
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"Ошибка: Файл '{filename}' не найден!")
|
||||
return []
|
||||
|
||||
return result
|
||||
8
TEMA7/test.txt
Обычный файл
8
TEMA7/test.txt
Обычный файл
@@ -0,0 +1,8 @@
|
||||
1,2,3,4,5
|
||||
100,200,300
|
||||
3.14,2.718,1.618,0.577
|
||||
один,два,три,четыре,пять
|
||||
-5,-10,-15,-20
|
||||
10.5,20.7,30.9
|
||||
строка1,строка2,строка3
|
||||
смешанные,данные,15,20.5,-7
|
||||
Ссылка в новой задаче
Block a user