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))
相关推荐
曲幽3 小时前
数据库实战:FastAPI + SQLAlchemy 2.0 + Alembic 从零搭建,踩坑实录
python·fastapi·web·sqlalchemy·db·asyncio·alembic
用户8356290780517 小时前
Python 实现 PowerPoint 形状动画设置
后端·python
ponponon9 小时前
时代的眼泪,nameko 和 eventlet 停止维护后的项目自救,升级和替代之路
python
Flittly9 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(5)Skills (技能加载)
python·agent
敏编程9 小时前
一天一个Python库:pyarrow - 大规模数据处理的利器
python
Flittly11 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(4)Subagents (子智能体)
python·agent
明月_清风17 小时前
Python 装饰器前传:如果不懂“闭包”,你只是在复刻代码
后端·python
明月_清风17 小时前
打破“死亡环联”:深挖 Python 分代回收与垃圾回收(GC)机制
后端·python
anOnion1 天前
构建无障碍组件之Switch Pattern
前端·html·交互设计
ZhengEnCi1 天前
08c. 检索算法与策略-混合检索
后端·python·算法