Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

alphanumeric list

11 views
Skip to first unread message

yqyq22

unread,
Mar 15, 2011, 4:10:05 AM3/15/11
to
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

Chris Rebert

unread,
Mar 15, 2011, 4:20:35 AM3/15/11
to yqyq22, pytho...@python.org

Can you show us your attempt?

Cheers,
Chris

yqyq22

unread,
Mar 15, 2011, 4:49:09 AM3/15/11
to

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


Ulrich Eckhardt

unread,
Mar 15, 2011, 4:44:53 AM3/15/11
to
yqyq22 wrote:
> 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

--
Domino Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

Ben Finney

unread,
Mar 15, 2011, 5:22:07 AM3/15/11
to
yqyq22 <yqy...@hotmail.com> writes:

> On Mar 15, 9:20 am, Chris Rebert <c...@rebertia.com> wrote:
> > Can you show us your attempt?
>

> Hi, to be honest i'm a newbye so i don't know where to start

Work through the entire Python tutorial, in sequence
<URL:http://docs.python.org/tutorial/>. Not merely read: work through
it, reading the explanations, performing the examples, and experimenting
with them until satisfied you understand, before moving on to the next.

--
\ “I was gratified to be able to answer promptly and I did. I |
`\ said I didn't know.” —Mark Twain, _Life on the Mississippi_ |
_o__) |
Ben Finney

Laurent Claessens

unread,
Mar 15, 2011, 6:02:22 AM3/15/11
to

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

Ulrich Eckhardt

unread,
Mar 15, 2011, 5:51:10 AM3/15/11
to
yqyq22 wrote:
> 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.

yqyq22

unread,
Mar 15, 2011, 9:15:53 AM3/15/11
to
On Mar 15, 11:02 am, Laurent Claessens <moky.m...@gmail.com> wrote:
> Le 15/03/2011 09:10, yqyq22 a crit :

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

yqyq22

unread,
Mar 16, 2011, 5:59:59 AM3/16/11
to
> 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

Laurent Claessens

unread,
Mar 16, 2011, 9:12:55 AM3/16/11
to yqyq22

> 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

Laurent Claessens

unread,
Mar 16, 2011, 9:13:03 AM3/16/11
to

> 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']

not1xor1 (Alessandro)

unread,
Mar 17, 2011, 12:39:04 AM3/17/11
to

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)

0 new messages