Skip to content

Commit caa48e9

Browse files
committed
1. Add ReverseList.py and traversal_directory.py
Signed-off-by: Jackey <mjjackey@163.com>
1 parent 3983a49 commit caa48e9

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

ReverseList.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Reverse a singly linked list.
3+
4+
Example:
5+
6+
Input: 1->2->3->4->5->NULL
7+
Output: 5->4->3->2->1->NULL
8+
Follow up:
9+
10+
A linked list can be reversed either iteratively or recursively. Could you implement both?
11+
"""
12+
class ListNode():
13+
def __init__(self,x):
14+
self.value = x
15+
nextNode = ListNode()
16+
self.next = nextNode
17+
18+
def ReverseList(pHead):
19+
pReverseHead = None
20+
21+
22+
23+
24+
25+
if __name__=="__main__":
26+
pass

decorator_log_var.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
Three layer packages for pass self-defined parameters
55
"""
66
import functools
7-
87
def log(para):
98
if(not isinstance(para,str)):
109
def wrapper(*args, **kw):
@@ -13,7 +12,7 @@ def wrapper(*args, **kw):
1312
return wrapper
1413
else:
1514
def decorator(func):
16-
# @functools.wraps(func)
15+
@functools.wraps(func)
1716
def wrapper(*args, **kw):
1817
print('%s %s():' % (para, func.__name__))
1918
return func(*args, **kw)
@@ -32,3 +31,4 @@ def f2():
3231
if __name__ == "__main__":
3332
f1()
3433
f2()
34+
print(f2.__name__)

traversal_directory.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
import shutil
3+
4+
5+
def rename_and_move_video_files(base_directory, target_directory):
6+
# Ensure the target directory exists
7+
if not os.path.exists(target_directory):
8+
os.makedirs(target_directory)
9+
10+
# Iterate through each item in the base directory
11+
for folder_name in os.listdir(base_directory):
12+
folder_path = os.path.join(base_directory, folder_name)
13+
14+
# Check if the item is a directory
15+
if os.path.isdir(folder_path):
16+
video_path = os.path.join(folder_path, 'video_left.avi')
17+
18+
new_name = f"{folder_name}.avi"
19+
new_video_path = os.path.join(folder_path, new_name)
20+
21+
# Check if video_left.avi exists in the directory
22+
if os.path.exists(video_path) or os.path.exists(new_video_path):
23+
if(os.path.exists(video_path)):
24+
# Rename the file
25+
os.rename(video_path, new_video_path)
26+
print(f"Renamed: {video_path} to {new_video_path}")
27+
28+
# Define the destination path
29+
destination_path = os.path.join(target_directory, new_name)
30+
31+
# Move the renamed file to the target directory
32+
shutil.move(new_video_path, destination_path)
33+
print(f"Moved: {new_video_path} to {destination_path}")
34+
35+
36+
# Path to the training set directory
37+
training_set_path = r'E:\DataSets\sar_rarp50\test_set'
38+
39+
# Path to the target directory where videos will be moved
40+
target_video_path = r'E:\DataSets\sar_rarp50\test_set_video'
41+
42+
# Call the function to rename and move the video files
43+
rename_and_move_video_files(training_set_path, target_video_path)
44+

0 commit comments

Comments
 (0)