关闭

随机组合名字的小程序

标签: python
574人阅读 评论(0) 收藏 举报
分类:
#!/usr/bin/env python3
# coding=utf-8

import os
import copy

def make_name(line, surname):
    L = [line.strip(),"\n"]
    count = 0
    line = line.replace(",","")
    line = line.replace("。","").strip()
    for first in line:
        new_line = list(copy.copy(line))
        new_line.remove(first)
        for second in new_line:
            L.append(surname+first+second+"  ")
            count += 1
            if count%10==0:
                L.append("\n")
    return L
def write_txt(path, surname="程"):
    try:
        os.remove("待选.txt")
    except:
        pass
    with open("待选.txt","a") as f:
        for line in open(path, "r"):
            f.writelines(make_name(line, surname))
            f.write("\n\n")


if __name__ == "__main__":
    write_txt("poem.txt")

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:91243次
    • 积分:2252
    • 等级:
    • 排名:第17417名
    • 原创:135篇
    • 转载:38篇
    • 译文:1篇
    • 评论:9条
    文章分类
    最新评论