Convert Figma logo to code with AI

geekcomputers logoPython

My Python Examples

30,913
12,138
30,913
381

Top Related Projects

Minimal examples of data structures and algorithms in Python

183,979

All Algorithms implemented in Python

An opinionated list of awesome Python frameworks, libraries, software and resources.

120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.

A collection of design patterns/idioms in Python

Python - 100天从新手到大师

Quick Overview

The geekcomputers/Python repository is a collection of Python scripts and programs created by the GeekComputers community. The repository covers a wide range of topics, from simple scripts to more complex applications, and serves as a valuable resource for Python learners and enthusiasts.

Pros

  • Diverse Content: The repository contains a wide variety of Python scripts and programs, covering a broad range of topics and use cases.
  • Active Community: The GeekComputers community is actively maintaining and contributing to the repository, ensuring regular updates and improvements.
  • Educational Value: The scripts and programs in the repository can be used as learning resources for those new to Python or looking to expand their knowledge.
  • Practical Applications: Many of the scripts and programs in the repository have practical applications, making them useful for real-world tasks.

Cons

  • Lack of Consistency: The repository contains scripts and programs contributed by various individuals, which can result in inconsistencies in coding style, documentation, and overall quality.
  • Varying Complexity: The repository includes scripts and programs of varying complexity, which may not be suitable for all users, especially those new to Python.
  • Limited Guidance: While the repository provides the code, it may lack detailed instructions or tutorials on how to use or customize the scripts and programs.
  • Potential Security Concerns: As with any open-source repository, users should exercise caution when running scripts or programs from the repository, as they may contain potential security vulnerabilities.

Code Examples

Here are a few short code examples from the geekcomputers/Python repository:

  1. Web Scraper:
import requests
from bs4 import BeautifulSoup

url = "https://www.example.com"
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")

# Extract the title of the webpage
title = soup.title.string
print(f"Title: {title}")

# Extract all the links on the webpage
links = [link.get("href") for link in soup.find_all("a")]
print(f"Links: {links}")

This code demonstrates a simple web scraper that extracts the title and all the links from a webpage.

  1. File Organizer:
import os
import shutil

# Set the directory to organize
directory = "/path/to/directory"

# Define the file extensions and their corresponding folders
file_extensions = {
    ".pdf": "PDFs",
    ".docx": "Documents",
    ".jpg": "Images",
    ".mp3": "Music"
}

# Organize the files in the directory
for filename in os.listdir(directory):
    file_extension = os.path.splitext(filename)[1].lower()
    if file_extension in file_extensions:
        source = os.path.join(directory, filename)
        destination = os.path.join(directory, file_extensions[file_extension], filename)
        os.makedirs(os.path.join(directory, file_extensions[file_extension]), exist_ok=True)
        shutil.move(source, destination)
        print(f"Moved {filename} to {file_extensions[file_extension]}")

This code organizes files in a directory based on their file extensions, moving them to corresponding folders.

  1. Password Generator:
import random
import string

def generate_password(length=12, include_digits=True, include_special_chars=True):
    """
    Generates a random password of the specified length.

    Args:
        length (int): The length of the password (default is 12).
        include_digits (bool): Whether to include digits in the password (default is True).
        include_special_chars (bool): Whether to include special characters in the password (default is True).

    Returns:
        str: The generated password.
    """
    characters = string.ascii_letters
    if include_digits:
        characters += string.digits
    if include_special_chars:
        characters += string.punctuation

    password = ''.join(random.choice(characters) for i in range(length))
    return password

# Example usage
password = generate_password()
print(f"Generated password: {password}")

This code defines a function to generate a random

Competitor Comparisons

Minimal examples of data structures and algorithms in Python

Pros of algorithms

  • Focused specifically on algorithm implementations and data structures
  • Well-organized into categories (e.g., sort, search, graph)
  • Includes explanations and complexity analysis for many algorithms

Cons of algorithms

  • Limited to algorithms and data structures, less general-purpose
  • Fewer contributors and less frequent updates
  • May be more challenging for beginners due to its specialized nature

Code comparison

algorithms:

def bubble_sort(arr):
    n = len(arr)
    for i in range(n):
        for j in range(0, n - i - 1):
            if arr[j] > arr[j + 1]:
                arr[j], arr[j + 1] = arr[j + 1], arr[j]
    return arr

Python:

def bubble(list):
    for iter_num in range(len(list)-1,0,-1):
        for idx in range(iter_num):
            if list[idx]>list[idx+1]:
                temp = list[idx]
                list[idx] = list[idx+1]
                list[idx+1] = temp

The algorithms implementation is more concise and uses Python's tuple unpacking for swapping elements, while the Python implementation uses a temporary variable and a reverse range for iteration.

183,979

All Algorithms implemented in Python

Pros of TheAlgorithms/Python

  • More comprehensive collection of algorithms and data structures
  • Better organized with clear categorization of algorithms
  • Actively maintained with frequent updates and contributions

Cons of TheAlgorithms/Python

  • May be overwhelming for beginners due to its extensive content
  • Less focus on practical, everyday Python scripts
  • Stricter contribution guidelines and code style requirements

Code Comparison

Python:

# Binary Search implementation
def binary_search(arr, x):
    low = 0
    high = len(arr) - 1
    while low <= high:
        mid = (low + high) // 2
        if arr[mid] < x:
            low = mid + 1
        elif arr[mid] > x:
            high = mid - 1
        else:
            return mid
    return -1

TheAlgorithms/Python:

# Binary Search implementation
def binary_search(array: list, target: int) -> int:
    left, right = 0, len(array) - 1
    while left <= right:
        mid = (left + right) // 2
        if array[mid] == target:
            return mid
        if array[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

The code comparison shows that TheAlgorithms/Python tends to use type hints and more descriptive variable names, while Python focuses on simplicity and readability. Both implementations are correct and efficient, but TheAlgorithms/Python adheres to stricter coding standards.

An opinionated list of awesome Python frameworks, libraries, software and resources.

Pros of awesome-python

  • Comprehensive curated list of Python resources, frameworks, and libraries
  • Well-organized into categories for easy navigation
  • Regularly updated with community contributions

Cons of awesome-python

  • Lacks actual code examples or tutorials
  • May be overwhelming for beginners due to the sheer volume of information

Code comparison

Not applicable, as awesome-python doesn't contain code samples, while Python primarily consists of code examples.

Python repository overview

Python is a collection of Python scripts and projects covering various topics and use cases. It serves as a learning resource for Python programmers of different skill levels.

awesome-python repository overview

awesome-python is a curated list of Python frameworks, libraries, software, and resources. It aims to be a comprehensive reference for Python developers looking for tools and resources in specific areas.

Key differences

  • Purpose: Python focuses on providing code examples, while awesome-python serves as a directory of resources
  • Content: Python contains actual Python scripts, whereas awesome-python consists of links and descriptions
  • Target audience: Python caters to learners and practitioners, while awesome-python is more suited for developers seeking specific tools or libraries

Recommendation

Choose Python for hands-on coding practice and examples. Opt for awesome-python when looking for a comprehensive list of Python resources and libraries for specific projects or learning paths.

120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.

Pros of interactive-coding-challenges

  • Focused on interview preparation with structured challenges
  • Includes comprehensive test cases and solutions
  • Covers a wide range of data structures and algorithms

Cons of interactive-coding-challenges

  • Less diverse in terms of general Python programming topics
  • May be overwhelming for beginners due to its advanced content
  • Requires more time investment to work through challenges

Code Comparison

Python:

def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)

interactive-coding-challenges:

class Solution(object):
    def factorial(self, n):
        if n == 0 or n == 1:
            return 1
        return n * self.factorial(n - 1)

Summary

Python offers a broader range of Python scripts and examples, making it suitable for general learning and reference. It's more accessible to beginners and covers various practical applications.

interactive-coding-challenges is specifically designed for coding interview preparation, offering a structured approach to learning data structures and algorithms. It's more suitable for intermediate to advanced programmers looking to enhance their problem-solving skills.

Both repositories have their merits, and the choice between them depends on the user's learning goals and experience level.

A collection of design patterns/idioms in Python

Pros of python-patterns

  • Focuses specifically on design patterns, providing a comprehensive resource for learning and implementing common software design solutions
  • Includes detailed explanations and examples for each pattern, making it easier for developers to understand and apply them
  • Regularly updated with new patterns and improvements, ensuring relevance to modern Python development practices

Cons of python-patterns

  • More specialized content, which may not be as useful for beginners or those looking for general Python programming examples
  • Smaller community and fewer contributors compared to Python, potentially resulting in slower updates and less diverse input

Code Comparison

Python (Basic file operations):

with open('filename.txt', 'r') as f:
    data = f.read()
print(data)

python-patterns (Singleton pattern):

class Singleton(type):
    _instances = {}
    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super().__call__(*args, **kwargs)
        return cls._instances[cls]

The Python repository provides more general-purpose code examples, while python-patterns focuses on specific design pattern implementations.

Python - 100天从新手到大师

Pros of Python-100-Days

  • Structured learning path with daily lessons
  • Comprehensive coverage of Python concepts and applications
  • Includes practical projects and exercises

Cons of Python-100-Days

  • May be overwhelming for absolute beginners
  • Less focus on individual script examples
  • Primarily in Chinese, which may limit accessibility for non-Chinese speakers

Code Comparison

Python-100-Days (Day 1 example):

print('hello, world!')
print('你好', '世界')
print('hello', 'world', sep=', ', end='!')
print('goodbye, world', end='!\n')

Python (example script):

import sys

if len(sys.argv) < 2:
    print("No file specified.")
    sys.exit(1)

filename = sys.argv[1]

Summary

Python-100-Days offers a structured learning approach with comprehensive coverage, while Python provides a collection of individual scripts for various tasks. Python-100-Days is better suited for those seeking a guided learning experience, whereas Python is more appropriate for users looking for specific script examples or quick solutions to common tasks.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

My Python Eggs 🐍 😄


I do not consider myself as a programmer. I create these little programs as experiments to play with Python, or to solve problems for myself. I would gladly accept pointers from others to improve, simplify, or make the code more efficient. If you would like to make any comments then please feel free to email me: craig@geekcomputers.co.uk.


This repository contains a collection of Python scripts that are designed to reduce human workload and serve as educational examples for beginners to get started with Python. The code documentation is aligned correctly for viewing in Notepad++ :spiral_notepad:

Feel free to explore the scripts and use them for your learning and automation needs!

List of Scripts:

  1. batch_file_rename.py - Batch rename a group of files in a specified directory, changing their extensions.
  2. create_dir_if_not_there.py - Check if a directory exists in the user's home directory. Create it if it doesn't exist.
  3. Fast Youtube Downloader - Download YouTube videos quickly with parallel threads using aria2c.
  4. Google Image Downloader - Query a given term and retrieve images from the Google Image database.
  5. dir_test.py - Test if the directory testdir exists. If not, create it.
  6. env_check.py - Check if all the required environment variables are set.
  7. blackjack.py - Casino Blackjack-21 game in Python.
  8. fileinfo.py - Show file information for a given file.
  9. folder_size.py - Scan the current directory and all subdirectories and display their sizes.
  10. logs.py - Search for all *.log files in a directory, zip them using the specified program, and date stamp them.
  11. move_files_over_x_days.py - Move all files over a specified age (in days) from the source directory to the destination directory.
  12. nslookup_check.py - Open the file server_list.txt and perform nslookup for each server to check the DNS entry.
  13. osinfo.py - Display information about the operating system on which the script is running.
  14. ping_servers.py - Ping the servers associated with the specified application group.
  15. ping_subnet.py - Scan the final range of a given IP subnet for available addresses.
  16. powerdown_startup.py - Ping machines in the server list. Load the putty session if the machine is up, or notify if it is not.
  17. puttylogs.py - Zip all the logs in the given directory.
  18. script_count.py - Scan the scripts directory and count the different types of scripts.
  19. get_youtube_view.py - Get more views for YouTube videos and repeat songs on YouTube.
  20. script_listing.py - List all files in a given directory and its subdirectories.
  21. testlines.py - Open a file and print out 100 lines of the set line variable.
  22. tweeter.py - Tweet text or a picture from the terminal.
  23. serial_scanner.py - List available serial ports in use on Linux and Windows systems.
  24. get_youtube_view.py - Get more views for YouTube videos and repeat songs on YouTube.
  25. CountMillionCharacter.py and CountMillionCharacter2.0 - Get character count of a text file.
  26. xkcd_downloader.py - Download the latest XKCD comic and place them in a new folder called "comics".
  27. timymodule.py - An alternative to Python's 'timeit' module and easier to use.
  28. calculator.py - Implement a calculator using Python's eval() function.
  29. Google_News.py - Use BeautifulSoup to provide latest news headlines along with news links.
  30. cricket_live_score - Use BeautifulSoup to provide live cricket scores.
  31. youtube.py - Take a song name as input and fetch the YouTube URL of the best matching song and play it.
  32. site_health.py - Check the health of a remote server.
  33. SimpleStopWatch.py - Simple stop watch implementation using Python's time module.
  34. Changemac.py - Change your MAC address, generate a random MAC address, or enter input as a new MAC address on Linux (Successfully Tested in Ubuntu 18.04).
  35. whatsapp-monitor.py - Use Selenium to give online status updates about your contacts in WhatsApp on the terminal.
  36. whatsapp-chat-analyzer.py - WhatsApp group/individual chat analyzer that visualizes chat activity using matplotlib.
  37. JARVIS.py - Control Windows programs with your voice.
  38. Images Downloader - Download images from webpages on Unix-based systems.
  39. space_invader.py.py - Classical 2D space invader game to recall your childhood memories.
  40. Test Case Generator - Generate different types of test cases with a clean and friendly UI, used in competitive programming and software testing.
  41. Extract Thumbnail From Video - Extract Thumbnail from video files
  42. How to begin the journey of open source (first contribution) - First Contribution of open source

Note: The content in this repository belongs to the respective authors and creators. I'm just providing a formatted README.md for better presentation.