By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,986 Members | 1,551 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,986 IT Pros & Developers. It's quick & easy.

how to shuffle elements of array

P: 1
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
Share this Question
Share on Google+
1 Reply


bartonc
Expert 5K+
P: 6,596
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.