List Info

Thread: reassign




reassign
user name
2007-04-08 04:38:26
Hi,
I have a list: [2,5,8,0,1,7]
how i can randomly reassign the values to different location
in the list?
for example:
Time 1: [5,2,8,0,1,7]
Time 2: [8,0,7,1,5,2]
Thanks!
Linda
_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

Re: reassign
country flaguser name
United Kingdom
2007-04-08 04:54:43
linda.s wrote:
> Hi,
> I have a list: [2,5,8,0,1,7]
> how i can randomly reassign the values to different
location in the list?
> for example:
> Time 1: [5,2,8,0,1,7]
> Time 2: [8,0,7,1,5,2]
>   
Have a look at the .shuffle function in the random module.

TJG
_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

Re: reassign
user name
2007-04-09 06:48:42
On 4/8/07, linda.s <samrobertsmithgmail.com> wrote:

> how i can randomly reassign the values to different
location in the list?

>>> import random
>>> mylist = [1,2,3,4,5,6,7,8,9]
>>> mylist
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> random.shuffle(mylist)
>>> mylist
[3, 6, 9, 4, 7, 1, 2, 8, 5]


-- 
- Rikard - http://bos.hack.org/cv/
_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

Re: reassign
user name
2007-04-14 02:19:18
I wonder how to use colors from gray to black to represent a
group of
values from small to large?
Thanks,
Linda
_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

Re: reassign
country flaguser name
United Kingdom
2007-04-14 07:40:17
"linda.s" <samrobertsmithgmail.com> wrote

>I wonder how to use colors from gray to black to
represent a group of
> values from small to large?

Can you explain what you mean? Normally colours are
represented
in code as a tuple of three numbers for the RGB values. If
its shades
of grey then all three numbers are the same so you only need
a
single number.

But you don't store colours in a program (except maybe as
string representations, eg 'cyan', 'blue', 'azure'). I'm not
sure what
you mean by using colours to represent values. Usually its
the other
way around?

If you do mean turning a range of values into shades of grey
then
thats faitrly easy, just scale your values between 0 and
255,
where black is (0,0,0) and white is (255,255,255). If you
have
N values then the scaling factor is 255/N. Then simply
multiply
the value by the factor...

Alan G. 


_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )