Home > database >  Create orderer names from a certain base
Create orderer names from a certain base

Time:10-17

I am stuck with this problem. I have to create a list of names like A0001, A0002... A0100 with all the alphabet letters. But I tried with the method random, and with some for loops, but I can not create the list with the names ["A0001"..."A0100"] it is done in python.

import numpy as np
import datetime
import re
import os
import random as rd
import string

letters = []
num = []
crias = []
numeros = []


# Crear lista del abecedario

def alphabet():
    x = list(string.ascii_uppercase)
    letters.append(x)
    return "Se han agregado las letras"


def numbers(n):
    for i in range(n   1):
        num.append(i)
        numeros.append([str(x) for x in num])


for l in letters:
    try:
        counter = 0
        crias.append(l[counter]   numeros)
    except:
        pass

numbers(int(input("Ingrese el numero de variables de nombre (1-n)")))
alphabet()

print(crias)

CodePudding user response:

Try this

import string

A = []
for L in string.ascii_uppercase:
    for n in ["{:.4f}".format(x/10000)[2:] for x in range(1, 101)]:
        A.append(L n)

CodePudding user response:

I assume you can do this if you like how it's read

A=[]
initial = "A0"

for i in range (1,101):
    if len(str(i)) == 1:
       A.append(initial "00" str(i))
    elif len(str(i)) == 2:
       A.append(initial "0" str(i))
    else:
       A.append(initial str(i))

of course you can automate adding the "00" in the middle too but I think doing it like this have a better readability and less overcomplicated it

  • Related