473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Re: arange randomly words in a list

I have a list that looks like:
>
name = name1 name2 name3 name4

and I would like to be able to arrange randomly this list, like:

name = name 2 name 1 name3 name4
name = name4 name2 name1 name3
....

I have tried with random.shuffle, but still no good result

May I get an example?
I'm not sure what you mean by "still no good result" as using
random.shuffle works quite nicely:
>>name = "name1 name2 name3 name4".split()
name
['name1', 'name2', 'name3', 'name4']
>>import random
random.shuffle(name)
name
['name1', 'name3', 'name4', 'name2']
>>print ' '.join(name)
name1 name3 name4 name2

which is exactly what you describe...

-tkc


Oct 25 '08 #1
0 993

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Joe Six-Pack | last post by:
Hi, Im having problems in randomly selecting an element in an array that has not been selected before.. in other words, I have an array of answers to questions, then I want to select 5, with one...
1
by: Benny Ng | last post by:
Hi,All, Export Method: ------------------------------------------------------------------------- strFileNameExport = "Results" Response.Clear() Response.Buffer = True...
5
by: Raghuram | last post by:
I want to generate some set of chars which are more than 4 chars randomly. . .. how can i do that
0
by: Shi Mu | last post by:
i got confused by the use of array and arange. arange get array and range get list, why we need the two different types?
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
2
by: engwar1 | last post by:
I'm building a page for a website that will allow for anonymous users to post comments. I want to filter out words deemed offensive or obscene. I know HOW to build this feature but I'm wondering if...
9
by: Alan Isaac | last post by:
I need access to 2*n random choices for two types subject to a constraint that in the end I have drawn n of each. I first tried:: def random_types(n,typelist=): types = typelist*n...
9
by: Generic Usenet Account | last post by:
I had a need to randomly select an element from an STL collection. It does not appear that this functionality is provided out-of-the-box with STL. Here is my crude implementation. I am using...
0
by: =?ISO-8859-1?Q?BJ=F6rn_Lindqvist?= | last post by:
2008/10/20 william paul <williampaul28@yahoo.com>: That is exactly what random.shuffle() does. Why doesn't the function work for you? -- mvh Björn
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.