traversal

How to visit all points in a 2D grid?

How to visit all points in a 2D grid? Question: I am trying to have 2 points visit all points in a 3 x 3 grid. The method of visiting the points is: I have points P1 and P2, starting from (0, 0). P1 moves from (0, 0) to (0, 1), (1, 0) until (3, …

Total answers: 1

Project Euler 11 Pyth0n

Project Euler 11 Pyth0n Question: I am trying to solve this puzzle but I cannot work out the logic that works for the example yet breaks for the solution! I think it has something to do with negative numbers for the directional list of tuples. Any advice would be most appreciated.! Here is the code …

Total answers: 4

NLTK: How do I traverse a noun phrase to return list of strings?

NLTK: How do I traverse a noun phrase to return list of strings? Question: In NLTK, how do I traverse a parsed sentence to return a list of noun phrase strings? I have two goals: (1) Create the list of Noun Phrases instead of printing them using the ‘traverse()’ method. I presently use StringIO to …

Total answers: 2

Find all occurrences of a key in nested dictionaries and lists

Find all occurrences of a key in nested dictionaries and lists Question: I have a dictionary like this: { "id": "abcde", "key1": "blah", "key2": "blah blah", "nestedlist": [ { "id": "qwerty", "nestednestedlist": [ { "id": "xyz", "keyA": "blah blah blah" }, { "id": "fghi", "keyZ": "blah blah blah" } ], "anothernestednestedlist": [ { "id": "asdf", …

Total answers: 12

List directory tree structure in python?

List directory tree structure in python? Question: I know that we can use os.walk() to list all sub-directories or all files in a directory. However, I would like to list the full directory tree content: – Subdirectory 1: – file11 – file12 – Sub-sub-directory 11: – file111 – file112 – Subdirectory 2: – file21 – …

Total answers: 17

Quicker to os.walk or glob?

Quicker to os.walk or glob? Question: I’m messing around with file lookups in python on a large hard disk. I’ve been looking at os.walk and glob. I usually use os.walk as I find it much neater and seems to be quicker (for usual size directories). Has anyone got any experience with them both and could …

Total answers: 4

Python os.walk + follow symlinks

Python os.walk + follow symlinks Question: How do I get this piece to follow symlinks in python 2.6? def load_recursive(self, path): for subdir, dirs, files in os.walk(path): for file in files: if file.endswith(‘.xml’): file_path = os.path.join(subdir, file) try: do_stuff(file_path) except: continue Asked By: fmalina || Source Answers: Set followlinks to True. This is the fourth …

Total answers: 1