I am trying to write a program in which the users will each enter their names and when all names have been entered, I want to randomly sort this list of names several times and then show the order in which they have beeen sorted. I tried using sort(), but this only sorts the names in the order in which they are entered. Any suggestions?
Thanks, Cisco 4 13239
On Sat, 23 Aug 2003 20:03:42 -0700 (PDT),
Frank & Janny Plaza <pl******@sbcgl obal.net> wrote: I am trying to write a program in which the users will each enter their names and when all names have been entered, I want to randomly sort this list of names several times and then show the order in which they have beeen sorted. I tried using sort(), but this only sorts the names in the order in which they are entered. Any suggestions?
I'm not quite sure what "sorts the names in the order in which
they are entered" means, but take a look at the shuffle function
in the random module: http://www.python.org/doc/current/li...le-random.html import random x = range( 10 ) x
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] random.shuffle( x ) x
[5, 8, 3, 0, 1, 7, 6, 9, 2, 4] random.shuffle( x ) x
[5, 2, 4, 1, 3, 9, 6, 0, 7, 8] random.shuffle( x ) x
[2, 8, 7, 5, 0, 4, 3, 9, 6, 1]
HTH,
Heather
--
Heather Coppersmith
That's not right; that's not even wrong. -- Wolfgang Pauli
Frank & Janny Plaza: I am trying to write a program in which the users will each enter their names and when all names have been entered, I want to randomly sort this list of names several times
[...] Thanks, Cisco
Hi Frank, Janny or Cisco!
My first idea was the following:
==============
import random
def shuffle(l):
randomly_tagged _list = [(random.random( ), x) for x in l]
randomly_tagged _list.sort()
return [x for (r, x) in randomly_tagged _list]
t=["Anna", "Berta", "Caesar", "Doris"]
print shuffle(t)
print shuffle(t)
print t
==============
You may want to also have a look at random.shuffle, however.
Greetings,
Carsten
--
Carsten Schultz (2:40, 33:47), FB Mathematik, FU Berlin http://carsten.fu-mathe-team.de/
PGP/GPG key on the pgp.net key servers,
fingerprint on my home page.
Hi!
Frank & Janny Plaza <pl******@sbcgl obal.net> wrote in
news:ma******** *************** ***********@pyt hon.org: I am trying to write a program in which the users will each enter their names and when all names have been entered, I want to randomly sort
"randomly sort"??????? I mean, for me "randomly" means somewhat of the
opposite of "sorted"...
Bye
Tobias
What about shuffle()?
"Tobias Pfeiffer" <Bo************ **@web.de> wrote in message
news:bk******** ****@ID-162581.news.uni-berlin.de... Hi!
Frank & Janny Plaza <pl******@sbcgl obal.net> wrote in news:ma******** *************** ***********@pyt hon.org:
I am trying to write a program in which the users will each enter their names and when all names have been entered, I want to randomly sort
"randomly sort"??????? I mean, for me "randomly" means somewhat of the opposite of "sorted"...
Bye Tobias This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jefferis NoSpamme |
last post by:
I have a query that is showing new items in a store based upon their
inventory date. The problem with my Random order sort is that when the
"next" link is pressed, the random function is called again and I may see
the image previously displayed rather than go through the entire new
inventory.
Any suggestions on how to prevent that occurrence?
SELECT *
FROM `Catalog`
|
by: Nhmiller |
last post by:
Is there a way to do this? Thanks.
Neil
Cat Paintings At Carol Wilson Gallery
http://www.carolwilsongallery.com
|
by: Kent |
last post by:
Hi!
I want to store data (of enemys in a game) as a linked list, each node will
look something like the following:
struct node
{
double x,y; // x and y position coordinates
struct enemy *enemydata; // Holds information about an enemy (in a game)
// Its a double linked list node
|
by: Paul Evans |
last post by:
Hi,
I've created a datagrid which works fine accept the id field (the primary
key field) comes out in a random order. How do I get the fields to display
sequencially?
Thanks for your time
Paul Evans
|
by: Tuxedo |
last post by:
I'd like to reorganize the third, fourth, fifth and sixth, as well as any
elements thereafter in an array in random order:
var a = new Array('first','second','third','fourth','fifth','sixth','etc')
In other words, the first, second and third element should remain in
position 0, 1 and 2, while the fourth, fifth and sixth, etc. should appear
in random order.
Can anyone recommend a method to do this?
| |
by: federicog |
last post by:
I have to create a listing in random order from a few mysql tables.
I can't use ORDER BY RAND() for a few reasons:
- The random order has to change only every 24hs, ie: today it will show rows number 4 2 3 1 and tomorrow 2 3 1 4, but it should be the same all day long.
- I'm dividing the results in pages using LIMIT x, y.
I suppose I would have to save the random order in a mysql table, but how can I order the results based on that...
|
by: dniom |
last post by:
Hi. Can you help me please?
Is there any way to show a unique random item from an array, every time you refresh the page? In other words how do I show the items from an array in random order, one by one, by reloading the page?
Moreover the page have to be refreshed by pressing the "submit" button...
Thats what I achieved so far :) but it doesn't display the UNIQUE array item every time the page is reloaded...
as you may guess :)
<html>...
|
by: Joe Cagg |
last post by:
I have looked All over the Internet to try and find an example of How to fix the following.
How to Sort a List in Desending Order by the "Value" and Sort the Duplicates by the "Key" ?
Then Print out the Results in the format below.
I have enclosed my code and it works, but the problem happens when there are duplicate values,
which occurs when you use SortedList(). I would GREATLY APPRECIATE it if someone could PLEASE Modify this
Code or...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |