471,330 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

how to shuffle elements of array

i want to shuffle the elements of an array without using random and shuffle functions.any one please help me.
ex:
input:a[1,2,3,4,5]
ouput:a[2,5,3,1,4]
Aug 17 '07 #1
1 4109
bartonc
6,596 Expert 4TB
i want to shuffle the elements of an array without using random and shuffle functions.any one please help me.
ex:
input:a[1,2,3,4,5]
ouput:a[2,5,3,1,4]
Expand|Select|Wrap|Line Numbers
  1. >>> numList = range(25)
  2. >>> numList
  3. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
  4. >>> dd = dict(zip(map(str, numList),numList))
  5. >>> [int(k) for k in dd.keys()]
  6. [24, 20, 21, 22, 23, 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18]
  7. >>> 
Aug 17 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

23 posts views Thread by JC | last post: by
24 posts views Thread by Joerg Schuster | last post: by
6 posts views Thread by CaseyB | last post: by
4 posts views Thread by Pratik | last post: by
25 posts views Thread by tooru honda | last post: by
4 posts views Thread by Aamir Mahmood | last post: by
2 posts views Thread by rubyhuang | last post: by
reply views Thread by rosydwin | last post: by

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.