python_将二维列表转换成HTML格式_邮件相关

python_将二维列表转换成HTML_邮件相关

复制代码
data=[["理想","2"],["理想2","3"]]

def list_to_html_table(data):
    """
    将二维列表转换为HTML表格格式的字符串。

    参数:
    data -- 二维列表,表示表格的数据。

    返回:
    一个字符串,包含HTML表格的表示。
    """
    # 开始构建HTML表格
    html = "<table border='1'>\n"  # 添加表格边框

    # 遍历二维列表的每一行
    for row in data:
        html += "  <tr>\n"  # 开始新的一行(tr)

        # 遍历行中的每一个元素(单元格)
        for cell in row:
            html += f"    <td>{cell}</td>\n"  # 添加单元格(td)

        html += "  </tr>\n"  # 结束当前行

    html += "</table>"  # 结束整个表格
    return html

print(list_to_html_table(data))
相关推荐
Csvn1 小时前
`functools.lru_cache` —— 一行代码搞定缓存加速
后端·python
anOnion12 小时前
构建无障碍组件之Menu Button pattern
前端·html·交互设计
金銀銅鐵17 小时前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup111 天前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi001 天前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
米丘1 天前
微前端之 Web Components 完全指南
微服务·html
金銀銅鐵1 天前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf1 天前
Agent 流程编排
后端·python·agent
copyer_xyf1 天前
Agent RAG
后端·python·agent