sort into folders
This commit is contained in:
C&C++
1st_day_of_month.cppJJbY.cppTp6G.cppalternatice_bracket.c
autoconfig
c.phpc_old_argument_notation.ccnn.ccomp.cconditional_const.cconst.ccpp_regex_error.cppcurrent_year.cppdda2.cppdog.jpgdog2.jpgelse_while.cflex
for_ctags.cppfree_null.cgcc_include_next.cgdb_graph.cgetopt_test.cgnu_decimals.cgnu_history.cgnu_regex.cgnu_regex2.cheader.hindex_in_initializer_list_compiler_extension.cknr.clevenshtein_dist_-_usage.cpplinking
map_initialization.cppncurses_labels.cncurses_mv_win.cppncurses_plus_readline.cppncurses_resize2.cppncurses_resize_hello_world.cppncurses_resize_test.cncurses_scroll.cnf.cnull_printf.cnull_printf.cppportable_namespace.cportable_namespace.hpta.cscoping_showcase.cscreen_size_(without_curses).csdl_render_to_texture.cppsentinel_pack.csetjmp_test.cppstrdup.ctcc_int.ctest.ctypedef.cunctrl.cundefined_reference.cusb.cvasprintf.cvoid_main.cx.cppxtermio.cxtp.cppMisc.
bind_test.sh
cross_compile
example.m4extension_cut.Makefilefizzbuzz.f90gdb_pretty_print
guards.hstest.infotest.texiPython
ascii_injection.pyascii_nn_input_helper.pydpt.pyformat.pygraph.pygroup.pyint_memory.ctype.pyint_memory.py.pyotest.pytkinter_filepicker_test.pytorus.py
Vim
Webdev
31
Python/group.py
Normal file
31
Python/group.py
Normal file
@ -0,0 +1,31 @@
|
||||
import difflib
|
||||
|
||||
# Example list of strings
|
||||
strings = [
|
||||
"apple pie",
|
||||
"apple cider",
|
||||
"apple juice",
|
||||
"banana bread",
|
||||
"banana split",
|
||||
"banana smoothie"
|
||||
]
|
||||
|
||||
# Create a dictionary to store the groups
|
||||
groups = {}
|
||||
|
||||
# Iterate through the strings to find the longest common substrings
|
||||
for i in range(len(strings)):
|
||||
for j in range(i+1, len(strings)):
|
||||
match = difflib.SequenceMatcher(None, strings[i], strings[j]).find_longest_match(0, len(strings[i]), 0, len(strings[j]))
|
||||
common_substring = strings[i][match.a: match.a + match.size]
|
||||
if common_substring:
|
||||
if common_substring not in groups:
|
||||
groups[common_substring] = [strings[i], strings[j]]
|
||||
else:
|
||||
groups[common_substring].extend([strings[i], strings[j]])
|
||||
|
||||
# Print the groups
|
||||
for key, value in groups.items():
|
||||
print(f"Group: {key}")
|
||||
print(value)
|
||||
print()
|
Reference in New Issue
Block a user