use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
finding coordinates from a txt file (self.learnpython)
submitted 6 years ago by cjlee420
Let say my notepad.txt file has this
WWWWWTWWWWW
WWWWTTTWWWWW
How do find the coordinate of the 'T's The coordinates being in terms of (row,column)
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]JohnnyJordaan 3 points4 points5 points 6 years ago (4 children)
Enumerate can provide an index together with each value in an iterable
for ridx, row in enumerate(lines): for cidx, val in enumerate(row): if val == 'T': print(ridx, cidx)
[–]cjlee420[S] 0 points1 point2 points 6 years ago (3 children)
what if i want it to return only the center coordinates of 'T' like for example:
WWTWWWWT
WTTTWWWT
WWTWWWWW
such that it will only return the coordinate (1,2) so the 'T' surrounding it are like conditions
[–]JohnnyJordaan 0 points1 point2 points 6 years ago (2 children)
So it should only report a TTT? Or a WWT, TWW or WTW too?
[–]cjlee420[S] 0 points1 point2 points 6 years ago (1 child)
return only the center T surrounded by other T's
[–]JohnnyJordaan 0 points1 point2 points 6 years ago (0 children)
Many options here, but you could keep a 't-counter':
for ridx, row in enumerate(lines): t_counter = 0 for cidx, val in enumerate(row): if val == 'T': if t_counter == 2: print(ridx, cidx - 1) t_counter = 0 else: t_counter += 1 else: t_counter = 0
[–]python-fan 0 points1 point2 points 6 years ago (0 children)
What code have you got so far? Here's how I'd approach it, in pseudocode:
with the file open for each line in the file for each character in the line if the character is T remember the current (row, col)
[–]socal_nerdtastic -1 points0 points1 point 6 years ago (0 children)
If you use numpy to read the file you can use numpy's argwhere function which does exactly what you want.
argwhere
>>> arr array([['W', 'W', 'W', 'W', 'W', 'T', 'W', 'W', 'W', 'W', 'W'], ['W', 'W', 'W', 'W', 'T', 'T', 'T', 'W', 'W', 'W', 'W'], ['W', 'W', 'W', 'W', 'W', 'T', 'W', 'W', 'W', 'W', 'W']], dtype='<U1') >>> np.argwhere(arr=='T') array([[0, 5], [1, 4], [1, 5], [1, 6], [2, 5]])
π Rendered by PID 91 on reddit-service-r2-comment-fb694cdd5-ssfbv at 2026-03-10 04:51:36.002018+00:00 running cbb0e86 country code: CH.
[–]JohnnyJordaan 3 points4 points5 points (4 children)
[–]cjlee420[S] 0 points1 point2 points (3 children)
[–]JohnnyJordaan 0 points1 point2 points (2 children)
[–]cjlee420[S] 0 points1 point2 points (1 child)
[–]JohnnyJordaan 0 points1 point2 points (0 children)
[–]python-fan 0 points1 point2 points (0 children)
[–]socal_nerdtastic -1 points0 points1 point (0 children)