Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Row Count and coloumn count
#4
world_data can be thought of as a grid, like a chessboard. "tile" is used to refer to the individual squares. A row is a group of tiles aligned in one direction, and a column is a group of tiles aligned in the other direction (often horizontal rows and vertical columns).

For your example:
world_data = [
[ 1 ,1 ,1, 1, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,1 ,1, 1, 1],
]
The first row is:
[ 1 ,1 ,1, 1, 1]
and the first column is
[ 1,
  1,
  1,
  1,
  1 ],
The way world_data is organized, it is very easy to loop through the rows, because each row is a list.
row[0] = [ 1 ,1 ,1, 1, 1]
row[1] = [ 1 ,0, 0, 0, 1]
row[2] = [ 1 ,0, 0, 0, 1]
row[3] = [ 1 ,0, 0, 0, 1]
row[4] = [ 1 ,1 ,1, 1, 1],
The "for row in data:" loop will run 5 times, once for each row shown above. The first time through the loop it uses row[0], the second time through the loop it uses row[1]. This continues until the last loop uses row[4].

"for tile in row:" works just like "for row in data", except this time it loops through the values in row. If row == row[1]:
tile[0] = 1
tile[1] = 0
tile[2] = 0
tile[3] = 0
tile[4] = 1
Reply


Messages In This Thread
Row Count and coloumn count - by Yegor123 - Oct-15-2022, 06:13 PM
RE: Row Count and coloumn count - by menator01 - Oct-15-2022, 06:31 PM
RE: Row Count and coloumn count - by Yegor123 - Oct-15-2022, 09:03 PM
RE: Row Count and coloumn count - by deanhystad - Oct-16-2022, 04:28 AM
RE: Row Count and coloumn count - by Yegor123 - Oct-18-2022, 03:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Count image's colors very fast flash77 18 1,830 Mar-05-2024, 06:12 PM
Last Post: deanhystad
  Function to count words in a list up to and including Sam Oldman45 15 6,819 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Strange argument count error rowan_bradley 3 799 Aug-06-2023, 10:58 AM
Last Post: rowan_bradley
  count certain task in task manager[solved] kucingkembar 2 1,187 Aug-29-2022, 05:57 PM
Last Post: kucingkembar
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,709 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  How to get unique entries in a list and the count of occurrence james2009 5 3,063 May-08-2022, 04:34 AM
Last Post: ndc85430
  df column mean and count of unique SriRajesh 0 1,140 May-07-2022, 08:19 AM
Last Post: SriRajesh
  Unable to count the number of tries in guessing game. Frankduc 7 2,011 Mar-20-2022, 08:16 PM
Last Post: menator01
  Problem : Count the number of Duplicates NeedHelpPython 3 4,486 Dec-16-2021, 06:53 AM
Last Post: Gribouillis
  Bot refuses to count logs. M1racle 0 1,292 Dec-13-2021, 06:42 PM
Last Post: M1racle

Forum Jump:

User Panel Messages

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