Python Forum
Best way to get data from 2D array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best way to get data from 2D array
#16
Look back at post #13, you have home_results = [] in the initialization. That's a problem. Lists are mutable, the are just passed as a reference to the list, not a copy of the list. Also, default parameters are stored in the function or method, and are not resolved every time the method is called. So every team's home_results is referencing the same list. That's why they have the same values in them.

I think the easiest solution here would be to remove that parameter from the parameter list. Instead just have home_results = [] in the body of the __init__ method. If it's in the body of the code, it will be resolved fresh each time the code is run, and you'll get five different lists.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Best way to get data from 2D array - by tobbs - Nov-11-2018, 03:13 PM
RE: Best way to get data from 2D array - by Larz60+ - Nov-11-2018, 05:31 PM
RE: Best way to get data from 2D array - by tobbs - Nov-11-2018, 06:36 PM
RE: Best way to get data from 2D array - by tobbs - Nov-13-2018, 05:39 PM
RE: Best way to get data from 2D array - by tobbs - Nov-16-2018, 06:22 PM
RE: Best way to get data from 2D array - by tobbs - Nov-18-2018, 01:10 PM
RE: Best way to get data from 2D array - by tobbs - Nov-18-2018, 05:53 PM
RE: Best way to get data from 2D array - by tobbs - Nov-20-2018, 06:12 PM
RE: Best way to get data from 2D array - by tobbs - Nov-21-2018, 08:04 PM
RE: Best way to get data from 2D array - by ichabod801 - Nov-22-2018, 02:18 AM
RE: Best way to get data from 2D array - by tobbs - Nov-22-2018, 06:44 PM
RE: Best way to get data from 2D array - by tobbs - Dec-12-2018, 08:36 PM
RE: Best way to get data from 2D array - by tobbs - Dec-13-2018, 07:04 PM
RE: Best way to get data from 2D array - by tobbs - Dec-13-2018, 08:27 PM
RE: Best way to get data from 2D array - by tobbs - Feb-19-2019, 04:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Seeing al the data in a dataframe or numpy.array Led_Zeppelin 1 1,226 Jul-11-2022, 08:54 PM
Last Post: Larz60+
Question Change elements of array based on position of input data Cola_Reb 6 2,247 May-13-2022, 12:57 PM
Last Post: Cola_Reb
  how to print all data from all data array? korenron 3 2,532 Dec-30-2020, 01:54 PM
Last Post: korenron
  Import CSV data into array and turn into integers DoctorSmiles 5 3,362 Jul-16-2020, 10:47 AM
Last Post: perfringo
  Issue with creating an array of pixel data for PNG files in Google Colab The_Sarco 1 1,996 Apr-29-2020, 12:03 AM
Last Post: bowlofred
  python3 List to array or string to extract data batchenr 4 3,388 May-28-2019, 01:44 PM
Last Post: buran
  Reading data from serial port as byte array vlad93 1 12,236 May-18-2019, 05:26 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020