I am fetching data for too many users from DB , the array in which all data is collected having two rows for each user , only last column value is different rest of the values are same like
r1 --> a , b , c , d , 1 (user1)
r2 -- > a , b , c , d , 2 (user1)
r3 --> z , x , v , n , 3 (user2)
r4 -- > z , x , v , n , 4 (user2)
Now I want to create an array which include only one row corresponding to each user but consist of every value like
r1 --> a , b , c , d , 1 , 2 (user1)
r2 -- >z , x , v , n , 3 , 4 (user2)
I have tried for loop , but the resulted array consist of only last record , I wanted an array which consist of all the records for all users.
e.g.
cursor.execute("some query ")
numrows = int(cursor.rowcount)
let this num rows returns value 4.
then
for I in range(numrows):
pass
will loop 4 times , but actually it consist the values for two users.
but when I returns the resulted array it consist the value of last user only.
So please suggest me some way so that when I do this for I in range(numrows): the array it returns consist of all the records not only last user record
Edited:
I have also tried while loop as
arr=[]
while arr in row:
arr= row[0][1]
but when i return this arr , it is empty but if i return row[0][1] then it shows the value of that column.
Thanks in advance.
Assuming that your data is sorted by first 4 entries (which you can do in your SQL), you can transform your data using the following code:
which prints
Here is another idea for you: use your first 4 entries as keys in a dictionary.
prints
With this approach it does not matter if your rows are sorted by first 4 columns