alphanumeric list
not1xor1 (Alessandro)
" " at libero.it
Thu Mar 17 00:39:04 EDT 2011
Il 15/03/2011 09:10, yqyq22 ha scritto:
> I would like to put an alphanumeric string like this one
> EE472A86441AF2E629DE360 in a list, then iterate inside the entire
> string lenght and change each digit with a random digit.
> Do u have some suggestion? thanks a lot
hi
I'm not an experienced python programmer but the following code should
work:
# you need to import the random module to get random numbers
import random
# convert the string in a list (as string are read-only)
l = list('EE472A86441AF2E629DE360')
# initialize the random generator
random.seed()
# index
i = 0
# loop through the characters in the list
for c in l:
# if the current character is a digit
if c.isdigit():
# get a random integer in the 0-9 range
# convert it to a string and replace the old value
l[i] = str(random.randint(0,9))
# increment the list index
i +=1
# convert the modified list back to string and display it
print(''.join(l))
--
bye
!(!1|1)
More information about the Python-list
mailing list