Python Exercise 1-Breadth-first search

Try dumping all the files under the specified directory with breadth-first search (BFS).

bfs.py


#!/usr/bin/env python
#-*- encoding:utf-8 *-*

import sys
import os
import glob

if len(sys.argv) != 2:
    print os.path.basename(sys.argv[0]) + ' <directory>'
    exit(None)

target_root = sys.argv[1]

que = []
que.append(target_root)

while len(que) > 0:
    target_dir = que.pop(0)
    for node in glob.glob(os.path.join(target_dir, '*')):
        if os.path.isdir(node):
            que.append(node)
        else:
            print(node)

exit(None)

Recommended Posts

Python Exercise 1-Breadth-first search
[Python] BFS (breadth-first search) ABC168D
Breadth-first search / bidirectional search (Python version)
[Python] Depth-first search and breadth-first search
[Python] BFS (breadth-first search) ABC007C
Algorithm in Python (breadth-first search, bfs)
Breadth-first search (BPF) Maybe understood (python)
Sequential search with Python
[Python] Search (itertools) ABC167C
Binary search in Python
[Python] Search (NumPy) ABC165C
Binary search (python2.7) memo
[Python] Binary search ABC155D
python bit full search
Linear search in Python
Binary search with python
Binary search with Python3
Search Twitter using Python
Binary search in Python (binary search)
I implemented breadth-first search in python (queue, drawing self-made)
Implement Depth-First Search (DFS) and Breadth-First Search (BFS) in python
Search for strings in Python
Search algorithm using word2vec [python]
Homebrew Python --Youtube Search Program
[Python] DFS (Depth-first Search) ATC001A
Binary search in Python / C ++
Algorithm in Python (binary search)
Full bit search with Python
[Python] DFS (Depth-first Search) ABC157D
Search engine work with python
Search twitter tweets with python
Streamline web search with python
Solving with Ruby and Python AtCoder ABC151 D Breadth-first search
Find the diameter of the graph by breadth-first search (Python memory)
Python
Python Exercise for Beginners # 2 [for Statement / While Statement]
Learn search with Python # 2bit search, permutation search
Algorithm in Python (depth-first search, dfs)
Master linear search! ~ Python implementation version ~
Write a depth-first search in Python
Reproduce One-Touch Search on Python 3.7.3. (Windows 10)
Depth-first search using stack in Python
Python 2-minute search and its derivation
Solve with Python [100 past questions that beginners and intermediates should solve] (028 --033 breadth-first search)
Solving with Ruby, Perl, Java, and Python AtCoder AGC 033 A Breadth-first search
Algorithm learned with Python 10th: Binary search
Homebrew Python Part 3-Amazon Product Search Program
Algorithm learned with Python 9th: Linear search
Algorithm in Python (ABC 146 C Binary Search
Search and play YouTube videos in Python
Search the maze with the python A * algorithm
In search of the fastest FizzBuzz in Python
Homebrew search from python module name (ShellScript)
Algorithm learned with Python 12th: Maze search