mirror of
https://github.com/hanzoai/aci.git
synced 2026-10-30 18:49:51 +00:00
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
import fnmatch
|
|
|
|
|
|
def find_matching_files_from_list(file_list, file_pattern):
|
|
"""
|
|
Find and return a list of file paths from the given list that match the given keyword or pattern.
|
|
|
|
:param file_list: A list of file paths to search through.
|
|
:param file_pattern: A keyword or pattern for file matching. Can be a simple keyword or a glob-style pattern.
|
|
|
|
:return: A list of matching file paths
|
|
"""
|
|
# If the pattern contains any of these glob-like characters, treat it as a glob pattern.
|
|
if '*' in file_pattern or '?' in file_pattern or '[' in file_pattern:
|
|
matching_files = fnmatch.filter(file_list, file_pattern)
|
|
else:
|
|
# Otherwise, treat it as a keyword search
|
|
matching_files = [file for file in file_list if file_pattern in file]
|
|
|
|
return matching_files
|
|
|
|
|
|
def merge_intervals(intervals):
|
|
# intervals inclusive
|
|
if not intervals:
|
|
return []
|
|
|
|
# Sort the intervals based on the starting value of each tuple
|
|
intervals.sort(key=lambda interval: interval[0])
|
|
|
|
merged_intervals = [intervals[0]]
|
|
|
|
for current in intervals[1:]:
|
|
last = merged_intervals[-1]
|
|
|
|
# Check if there is overlap
|
|
if current[0] <= last[1]:
|
|
# If there is overlap, merge the intervals
|
|
merged_intervals[-1] = (last[0], max(last[1], current[1]))
|
|
else:
|
|
# If there is no overlap, just add the current interval to the result list
|
|
merged_intervals.append(current)
|
|
|
|
return merged_intervals
|