alphanumeric list

Y

yqyq22

Hi all,
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
 
C

Chris Rebert

Hi all,
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

Can you show us your attempt?

Cheers,
Chris
 
U

Ulrich Eckhardt

yqyq22 said:
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.

What does "change each digit with a random digit"? Do you want to swap two
random elements of the sequence with each other? The "random" module
contains a tool to generate random permutations, all you would have to do
is to split the string into a list, call that function and later join the
results.

Uli
 
Y

yqyq22

Can you show us your attempt?

Cheers,
Chris

Hi, to be honest i'm a newbye so i don't know where to start, i began
in this way but i don't know how to proceeed.
list = (EE472A86441AF2E629DE360)
Thanks
 
U

Ulrich Eckhardt

yqyq22 said:
Hi, to be honest i'm a newbye so i don't know where to start, i began
in this way but i don't know how to proceeed.
list = (EE472A86441AF2E629DE360)

"list" is a builtin type, so you shouldn't use it as name for other things.
The thing on the right-hand side of the assignment is just the identifier
EE47... after stripping the brackets, which don't have a meaning there.

I'd suggest that you start reading a Python tutorial to get some basics down
first. Start reading at http://docs.python.org.

Uli
 
L

Laurent Claessens

Le 15/03/2011 09:10, yqyq22 a écrit :
Hi all,
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

This can be a way to begin :

s="EE472A86441AF2E629DE360"
for a in s:
print a

The following is a very basic trick to build a list <t> containing the
elements of the string <s>

s="EE472A86441AF2E629DE360"
t=[]
for a in s:
t.append(a)

All that you have to change is t.append(a) into something that
tests if a is a number and append something else in that case.

Depending what you want, you can even do

s.replace("1","ONE").replace("2","TWO").replace("3","FIVE")

This is however far from being random ;)

Have good tests
Laurent
 
Y

yqyq22

Le 15/03/2011 09:10, yqyq22 a crit :
Hi all,
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

This can be a way to begin :

s="EE472A86441AF2E629DE360"
for a in s:
    print a

The following is a very basic trick to build a list <t> containing the
elements of the string <s>

s="EE472A86441AF2E629DE360"
t=[]
for a in s:
    t.append(a)

All that you have to change is t.append(a) into something that
tests if a is a number and append something else in that case.

Depending what you want, you can even do

s.replace("1","ONE").replace("2","TWO").replace("3","FIVE")

This is however far from being random ;)

Have good tests
Laurent

Laurent thanks a lot very much!!! really appreciated it.. now i have a
good start point thanks again
 
Y

yqyq22

Le 15/03/2011 09:10, yqyq22 a crit :
This can be a way to begin :
s="EE472A86441AF2E629DE360"
for a in s:
    print a
The following is a very basic trick to build a list <t> containing the
elements of the string <s>
s="EE472A86441AF2E629DE360"
t=[]
for a in s:
    t.append(a)
All that you have to change is t.append(a) into something that
tests if a is a number and append something else in that case.
Depending what you want, you can even do

This is however far from being random ;)
Have good tests
Laurent

Laurent thanks a lot very much!!! really appreciated it.. now i have a
good start point thanks again- Hide quoted text -

- Show quoted text -

Something like that but it append A to each element of the string

string = "EE472B"
t = []
for x in string[:]:
print t.append("A") #i don't want to append A, the final
result is EAEA4A7A2ABA
# i would like to substitute each element with a random
string

How i can use the random module in this case? Thanks
 
L

Laurent Claessens

string = "EE472B"
t = []
for x in string[:]:
print t.append("A") #i don't want to append A, the final
result is EAEA4A7A2ABA

As it, it prints "None" 6 times. Then t is ['A','A','A','A','A']

What you have to do is to read about basic python. Search for python
tutorial on the net.

Then try the following exercices :

Exercises

1
print the first 1000 intergers

2
print the sine of 1 ... 1000

3
print the intergers x between 1 and 1000 such that cos(x) is between 0
and 0.5


Have a good afternoon
Laurent
 
L

Laurent Claessens

string = "EE472B"
t = []
for x in string[:]:
print t.append("A") #i don't want to append A, the final
result is EAEA4A7A2ABA

As it, it prints "None" 6 times. Then t is ['A','A','A','A','A']

What you have to do is to read about basic python. Search for python
tutorial on the net.

Then try the following exercices :

Exercises

1
print the first 1000 intergers

2
print the sine of 1 ... 1000

3
print the intergers x between 1 and 1000 such that cos(x) is between 0
and 0.5


Have a good afternoon
Laurent
 
N

not1xor1 (Alessandro)

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 = str(random.randint(0,9))
# increment the list index
i +=1
# convert the modified list back to string and display it
print(''.join(l))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top