473,395 Members | 1,568 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,395 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 992

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.