Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cnt = 0
- wb = load_workbook('zhuk.xlsx')
- sheet = wb['Лист5']
- # Загрузили 1 строчку
- prev_line = list()
- for cellObj in sheet['B2':'O2']:
- for cell in cellObj:
- prev_line.append(cell.value)
- # Обработали 1 строчку
- check = False
- for i in range(len(prev_line)):
- if prev_line[i] == -1 and not check:
- cnt += 1
- prev_line[i] = cnt
- check = True
- elif prev_line[i] == -1 and check:
- prev_line[i] = cnt
- elif prev_line[i] == 0:
- check = False
- print(prev_line)
- # Загружаем по 1 строчке, начиная со 2-й
- for cellObj in sheet['B3':'O22']:
- line = list()
- for cell in cellObj:
- line.append(cell.value)
- # Обрабатываем
- check = False
- for i in range(len(line)):
- if line[i] == -1 and not check and prev_line[i] != 0:
- check = True
- line[i] = prev_line[i]
- elif line[i] == -1 and not check and prev_line[i] == 0:
- check = True
- cnt += 1
- line[i] = cnt
- elif line[i] == -1 and check and prev_line[i] == 0:
- line[i] = line[i - 1]
- elif line[i] == -1 and check and prev_line[i] != 0:
- if prev_line[i] != cnt:
- cnt -= 1
- line[i] = cnt
- elif line[i] == 0:
- check = False
- prev_line = line
- print(line)
- print('Answer is:', cnt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement