Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Say I had an array in this fashion: somearray[name][gender][year] Im trying to m

ID: 3744067 • Letter: S

Question

Say I had an array in this fashion:

somearray[name][gender][year]

Im trying to make another array in the same format from the first array. However this new array is only supposed to contain the names that start with A, if it does start with A it needs to go in this new array named Aarray, and if it doesn't start with A then it would just skip over it and go to the next name. So names like Anna, Abby, Angelica, Ace, etc. would be in this new array but names like Becky, Charles, Chad, Louis all would not. The Aarray is in the same format like so:

Aarray[name][gender][year]

My question is how to take all the nemes that start with A in the first somearray and put them all into the Aarray. Any code or assistance on this would be helpful.

Explanation / Answer

When you are saying you have an array 'somearray' which is holding values for 3 different fields, you dont need a 3 dimensional array. use a 2 dimensional array of size [3][n]. This will give you 3 columns and n rows.

so the structure for 'somearray' would be like: somearray[3][n], where 0 = name, 1 = gender and 2 = year.

So now, when you address like this : somearray[0][5], it will give you he 5th element in the 'name' field's array. somearray[1][7] will give you 7th element in the 'gender' field's array.

Then, you can move forward to selecting out the names that starts with 'A'. for that, I'm providing a simple python code:

for i in range(n):
   name = somearray[0][i]
   if(name[0]== 'A' or name[0] == 'a'):
       Aarray[0][i] = somearray[0][i]
       Aarray[1][i] = somearray[1][i]
       Aarray[2][i] = somearray[2][i]          

This will check the 0th field, i.e. the 'name' field of every entry in 'somearray' and extracts the 'name', then uut checks if the name string's 1st character is 'A' or 'a', if it is, it will copy all the field entries (name, gender and year) of that index (i) to your Aarray[][]

Hope this helps. Feel free to post a comment if you have any problems with the answer. Give it a thumbs up if you are satisfied, it helps a lot.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote