|
139 | 139 | "tags": ["python", "string", "word-count", "utility"],
|
140 | 140 | "author": "axorax"
|
141 | 141 | },
|
142 |
| - { |
143 |
| - "title": "Replace Substring", |
144 |
| - "description": "Replaces all occurrences of a substring in a string with another substring.", |
145 |
| - "code": [ |
146 |
| - "def replace_substring(s, old, new):", |
147 |
| - " return s.replace(old, new)", |
148 |
| - "", |
149 |
| - "# Usage:", |
150 |
| - "print(replace_substring('hello world', 'world', 'Python')) # Output: 'hello Python'" |
151 |
| - ], |
152 |
| - "tags": ["python", "string", "replace", "utility"], |
153 |
| - "author": "axorax" |
154 |
| - }, |
155 | 142 | {
|
156 | 143 | "title": "Split Camel Case",
|
157 | 144 | "description": "Splits a camel case string into separate words.",
|
|
195 | 182 | "tags": ["python", "string", "whitespace", "remove", "utility"],
|
196 | 183 | "author": "axorax"
|
197 | 184 | },
|
198 |
| - { |
199 |
| - "title": "Swap Case", |
200 |
| - "description": "Swaps the case of all characters in a string.", |
201 |
| - "code": [ |
202 |
| - "def swap_case(s):", |
203 |
| - " return s.swapcase()", |
204 |
| - "", |
205 |
| - "# Usage:", |
206 |
| - "print(swap_case('Hello World')) # Output: 'hELLO wORLD'" |
207 |
| - ], |
208 |
| - "tags": ["python", "string", "case", "swap", "utility"], |
209 |
| - "author": "axorax" |
210 |
| - }, |
211 | 185 | {
|
212 | 186 | "title": "Find All Substrings",
|
213 | 187 | "description": "Finds all substrings of a given string.",
|
|
475 | 449 | "tags": ["python", "file", "copy", "utility"],
|
476 | 450 | "author": "axorax"
|
477 | 451 | },
|
478 |
| - { |
479 |
| - "title": "Rename File", |
480 |
| - "description": "Renames a file from its current name to a new name.", |
481 |
| - "code": [ |
482 |
| - "import os", |
483 |
| - "", |
484 |
| - "def rename_file(old_name, new_name):", |
485 |
| - " if os.path.exists(old_name):", |
486 |
| - " os.rename(old_name, new_name)", |
487 |
| - " print(f'File renamed from {old_name} to {new_name}')", |
488 |
| - " else:", |
489 |
| - " print(f'File {old_name} does not exist.')", |
490 |
| - "", |
491 |
| - "# Usage:", |
492 |
| - "rename_file('example.txt', 'new_example.txt')" |
493 |
| - ], |
494 |
| - "tags": ["python", "file", "rename", "utility"], |
495 |
| - "author": "axorax" |
496 |
| - }, |
497 | 452 | {
|
498 | 453 | "title": "List Files in Directory",
|
499 | 454 | "description": "Lists all files in a specified directory.",
|
|
579 | 534 | "tags": ["python", "math", "prime", "check"],
|
580 | 535 | "author": "dostonnabotov"
|
581 | 536 | },
|
582 |
| - { |
583 |
| - "title": "Generate Fibonacci Sequence", |
584 |
| - "description": "Generates a Fibonacci sequence up to a given number of terms.", |
585 |
| - "code": [ |
586 |
| - "def generate_fibonacci(n):", |
587 |
| - " sequence = [0, 1]", |
588 |
| - " for _ in range(2, n):", |
589 |
| - " sequence.append(sequence[-1] + sequence[-2])", |
590 |
| - " return sequence[:n]", |
591 |
| - "", |
592 |
| - "# Usage:", |
593 |
| - "print(generate_fibonacci(10)) # Output: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]" |
594 |
| - ], |
595 |
| - "tags": ["python", "math", "fibonacci", "sequence"], |
596 |
| - "author": "axorax" |
597 |
| - }, |
598 | 537 | {
|
599 | 538 | "title": "Check Perfect Square",
|
600 | 539 | "description": "Checks if a number is a perfect square.",
|
|
626 | 565 | "tags": ["python", "math", "binary", "decimal", "conversion"],
|
627 | 566 | "author": "axorax"
|
628 | 567 | },
|
629 |
| - { |
630 |
| - "title": "Generate Random Number", |
631 |
| - "description": "Generates a random number within a given range.", |
632 |
| - "code": [ |
633 |
| - "import random", |
634 |
| - "", |
635 |
| - "def generate_random_number(start, end):", |
636 |
| - " return random.randint(start, end)", |
637 |
| - "", |
638 |
| - "# Usage:", |
639 |
| - "print(generate_random_number(1, 100)) # Output: A random number between 1 and 100" |
640 |
| - ], |
641 |
| - "tags": ["python", "math", "random", "utility"], |
642 |
| - "author": "axorax" |
643 |
| - }, |
644 |
| - { |
645 |
| - "title": "Calculate GCD (Greatest Common Divisor)", |
646 |
| - "description": "Calculates the greatest common divisor (GCD) of two numbers using Euclid's algorithm.", |
647 |
| - "code": [ |
648 |
| - "def gcd(a, b):", |
649 |
| - " while b:", |
650 |
| - " a, b = b, a % b", |
651 |
| - " return a", |
652 |
| - "", |
653 |
| - "# Usage:", |
654 |
| - "print(gcd(56, 98)) # Output: 14", |
655 |
| - "print(gcd(101, 10)) # Output: 1" |
656 |
| - ], |
657 |
| - "tags": ["python", "math", "gcd", "algorithm"], |
658 |
| - "author": "axorax" |
659 |
| - }, |
660 | 568 | {
|
661 | 569 | "title": "Find LCM (Least Common Multiple)",
|
662 | 570 | "description": "Calculates the least common multiple (LCM) of two numbers.",
|
|
0 commit comments