alphanumeric list

Discussion in 'Python' started by yqyq22, Mar 15, 2011.

  1. yqyq22

    yqyq22 Guest

    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
    yqyq22, Mar 15, 2011
    #1
    1. Advertising

  2. yqyq22

    Chris Rebert Guest

    On Tue, Mar 15, 2011 at 1:10 AM, yqyq22 <> wrote:
    > 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
    Chris Rebert, Mar 15, 2011
    #2
    1. Advertising

  3. 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
    Ulrich Eckhardt, Mar 15, 2011
    #3
  4. yqyq22

    yqyq22 Guest

    On Mar 15, 9:20 am, Chris Rebert <> wrote:
    > On Tue, Mar 15, 2011 at 1:10 AM, yqyq22 <> wrote:
    > > 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


    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
    yqyq22, Mar 15, 2011
    #4
  5. 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.

    Uli

    --
    Domino Laser GmbH
    Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
    Ulrich Eckhardt, Mar 15, 2011
    #5
  6. 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 Claessens, Mar 15, 2011
    #6
  7. yqyq22

    yqyq22 Guest

    On Mar 15, 11:02 am, Laurent Claessens <> wrote:
    > 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
    yqyq22, Mar 15, 2011
    #7
  8. yqyq22

    yqyq22 Guest

    On Mar 15, 2:15 pm, yqyq22 <> wrote:
    > On Mar 15, 11:02 am, Laurent Claessens <> wrote:
    >
    >
    >
    >
    >
    > > 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- 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
    yqyq22, Mar 16, 2011
    #8

  9. > 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, Mar 16, 2011
    #9

  10. > 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, Mar 16, 2011
    #10
  11. 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))

    --
    bye
    !(!1|1)
    not1xor1 (Alessandro), Mar 17, 2011
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer

    Check if var is alphanumeric?

    VB Programmer, Nov 16, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    564
    bruce barker
    Nov 16, 2004
  2. Steven J Sobol
    Replies:
    8
    Views:
    5,642
    Thomas Weidenfeller
    Apr 30, 2004
  3. Paul
    Replies:
    1
    Views:
    13,153
    Rogan Dawes
    Sep 14, 2004
  4. Alphanumeric font

    , Dec 17, 2004, in forum: Java
    Replies:
    2
    Views:
    2,158
    Geli J. Crick
    Dec 17, 2004
  5. enrique
    Replies:
    2
    Views:
    538
Loading...

Share This Page