Files
2025-02-Algorithm/reviews/__pyfunc__/r6.py
2025-09-28 20:56:53 +09:00

55 lines
1.4 KiB
Python

from bs4 import BeautifulSoup
def create_array_table(data: list, border: list, cnt_p1: int, cnt_p2: int) -> str:
STYLE_ARRAY_TABLE = "border-collapse: collapse;"
STYLE_TD_TEMPLATE = "border: 1px solid black; width: 1.2em; height: 1.6rem; text-align: center; font-size: 1.3rem;"
def style_with_rborder(style: str):
style += "border-right: 6px solid black;"
return style
def style_with_p1(style: str):
style += "background-color: lightgray;"
return style
def style_with_p2(style: str):
style += "background-color: gray;"
return style
if len(data) != len(border):
return ""
soup = BeautifulSoup("", "html.parser")
table = soup.new_tag('table', attrs={'style': STYLE_ARRAY_TABLE})
tr = soup.new_tag('tr')
for i in range(len(data)):
style = STYLE_TD_TEMPLATE
if i < cnt_p1:
style = style_with_p1(style)
if border[i]:
style = style_with_rborder(style)
elif cnt_p1 <= i < cnt_p1 + cnt_p2:
style = style_with_p2(style)
if border[i]:
style = style_with_rborder(style)
else:
if border[i]:
style = style_with_rborder(style)
td = soup.new_tag('td', attrs={'style': style})
td.string = str(data[i])
tr.append(td)
table.append(tr)
soup.append(table)
return str(soup)