Could anyone please suggest on how to fetch original data position of any element from an array even if the array gets randomized/shuffled.
e.g. my original array is: arr=[a,b,c,d,e]
and, arr[2] will return: [c]
and, after random.shuffle(arr) the output is=[c,a,e,d,b]
and, arr[2] will return: [e]
But, I still wanted to see the same result as from original array i.e. I should still get arr[2]=[c] even if I have randomized my array.
Please help in solving this query, thanks for your help on this!
Regards,
Akhilesh Gupta
1 1596 bvdet 2,851
Expert Mod 2GB
You will have to save the original state of the list in some manner. This is sort of convoluted but seems to work: - import random
-
-
arr=['0', '1', '2', '3', '4', '5']
-
-
dd = {}
-
for i, item in enumerate(arr):
-
dd[i] = item
-
random.shuffle(arr)
-
print arr
-
-
i = arr.index(dd[2])
-
-
print arr[i]
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: JKop |
last post by:
template<class T>
inline T& NthArrayMember( T & (array),size_t i)
{
return array;
}
template<class T>
inline const T& NthArrayMember( const T & (array),size_t i)
{
return array;
|
by: Geoff Cox |
last post by:
Hello,
This may be the answer to a problem I have - or it may not be
possible?!
Can I have initial values of variable situation and count defined as
var situation = 0;
var count = 0;
|
by: fdunne2 |
last post by:
Hi,
Is there a function in C that returns the max value in an array? I need a function that returns the max value and the corresponding array index.
Also, when reading float values from a...
|
by: worli |
last post by:
Hi All,
I have a strange requirement.
I have a dynamic input numeric data stream e.g. 2, 2, 4, 5 etc....
( each input number range from 1 to 10 ).
lets take a simple case where all inputs will...
|
by: Amrit Kohli |
last post by:
Hello.
I have the following code, to do a simple operation by copying the elements
of a vector of strings into an array of char pointers. However, when I run
this code, the first element in the...
|
by: avharut |
last post by:
hello everyone!
sorry to disturb you with this, but i really cant find anything
suitable about the topic in the numarray documentation.
how can i find in an efficient way the index of the last...
|
by: aqazi |
last post by:
Hi guys I am having a problem with arrayu manipulation.
in my php script i am reading from a csv file.
the content of file is like this:
name,color,quantity,price;
apple,red,10,$2;...
|
by: =?big5?B?r0W84Q==?= |
last post by:
Hi All C gurus:
Below is a small program to print out the address of array and
address of array variable:
int main() {
char array = "haha";
printf("array:%x\n", array);
printf("&array:%x\n",...
|
by: =?utf-8?B?5YiY5piK?= |
last post by:
Hi, folks,
Is it possible to delete an element from a sorted array with O(1)
time?
Best regards
|
by: choke |
last post by:
I need to write a function in devc++ that creates an array of n integers, each element is equal to n*n+i*i-n*i where i is from 0 to n-1 as the array index. Within the same function I need to find...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: 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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |