Hi,
I'm trying to generate a list of random digits with no repeats. So far i have:
a = random.sample(r ange(0, 1), n)
which generates a list of random digits in a list with no repeat such as [1, 3, 5, 9] where n is 4.
However, i need it to produce a list of string of digits with no repeats, such as ['1', '3', '5', '9']. Is there any simple way to do this?
Thankyou for r...
User Profile
Collapse
-
generate list of strings
-
that's brilliant! and so simple!
Thanks heaps :)... -
split 1234 into ('1', '2', '3', '4')
Hi,
I was wondering if there is a simple way to split 1234 into a string of ('1', '2', '3', '4').
Also, is there a way to test whether an element of a string (or list) is an integer. For instance, if i had a list a = ['1', '2', '3', '4'], the elements are all integers, the function needs to return True.
However, if the list was ['1', '2', '3', 'x'], how would i distinguish that 'x' is not an integer and... -
Yes, thankyou :) That helped a lot. I ended up using a while loop, but it seems to work well.
Thanks!...Leave a comment:
-
so far i have used
random.sample(r ange(0, 10), n) where n is the number of digits long.
This works really well for getting a random list with no repeats, but i need to have a random list where repeats are allowed.Leave a comment:
-
Generate Random List of Integers
Hi,
I'm really new to python or really any programming at all. I'm trying to write a game and I'm really stuck on one small, seemingly easy task.
I have to generate a random list of n single digit integers (0 to 9).
For example, ['1', '5', '2', '8'] where n is 4.
Please help! I'm going out of my mind!
Thanks heaps
No activity results to display
Show More
Leave a comment: