SShortSingh.
Back to feed

Python List Slicing Explained: Syntax, Examples, and Advanced Tips

0
·3 views

A tutorial published on DEV Community covers list and string slicing in Python as part of Sololearn's Introduction to Python course, Module Four. Slicing allows developers to extract specific portions of ordered sequences such as lists and strings using index-based syntax with square brackets and a colon. The starting index is inclusive while the stopping index is exclusive, meaning slice [0:3] returns the first three elements but not the fourth. Developers can also omit the starting index to slice from the beginning, or omit the stopping index to slice through to the end of a sequence. The tutorial includes practical code examples using a pizza toppings list to demonstrate both basic and advanced slicing techniques.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

How Engineers Build Reliable Data Transmission on Top of UDP

UDP is a lightweight networking protocol that powers real-time applications like online games, video streaming, voice calls, and DNS, but unlike TCP it offers no guarantees of delivery, order, or duplicate prevention. Because of this, engineers sometimes prefer UDP when they need fine-grained control over how data is transmitted, rather than accepting TCP's built-in overhead. A technique known as 'reliable UDP' involves layering custom mechanisms — such as sequence numbers, acknowledgements, retransmissions, and duplicate detection — directly on top of UDP. This approach lets developers rebuild only the reliability features their specific application actually needs, avoiding unnecessary costs like head-of-line blocking or connection setup delays. The result is a tailored transport layer that can outperform TCP in latency-sensitive scenarios while still ensuring data integrity where it matters.

0
ProgrammingDEV Community ·

How One Wildcard DNS Record Powered 19 Self-Hosted Services Behind a Single IP

A self-hosted infrastructure setup using a single wildcard DNS record (*.example.com) routes all subdomains to one VPS, with Nginx Proxy Manager handling HTTPS publishing through a simple four-field form. The author automated service deployment using Claude Code, which generates compose files, proxy configurations, and certificates end-to-end, resulting in 19 live public hostnames. Each service received its own Let's Encrypt certificate via HTTP-01 challenge rather than a shared wildcard certificate, which permanently requires port 80 to remain open for renewals — a silent failure risk if closed. The author notes that the ease of publishing services exposed a key oversight: none of the tooling enforces access control, leaving all 19 services reachable from the open internet by default. The intended solution was to make the services accessible only through a private overlay network, separating the concept of being internet-connected from being publicly reachable.

0
ProgrammingDEV Community ·

Bot Token vs Full Account Access: What Telegram-Claude Integrations Really Mean

Connecting Claude to Telegram via the Model Context Protocol (MCP) can be done in minutes, but users face two fundamentally different setups with very different security implications. Bot API servers authenticate using a limited bot token, restricting access only to chats the bot is explicitly added to, while MTProto servers log in as the user, exposing all private messages, groups, and contacts. The session file created by MTProto does not expire like a token and can be exploited by anyone who gains access to it, making secure storage critical. Beyond credential theft, granting an AI agent full read-write access to Telegram introduces prompt injection risks, since a malicious message crafted as a command could manipulate the agent. The article also highlights practical pitfalls such as differing config file locations across AI clients and Codex CLI requiring TOML rather than JSON format.

0
ProgrammingDEV Community ·

How to Estimate and Control Costs in RAG-Based Semantic Search Apps

Retrieval-Augmented Generation (RAG) systems incur costs across three distinct stages: document embedding during indexing, retrieval-time processing, and answer generation using chat models. Developers can keep expenses predictable by splitting documents into chunks, generating embeddings in batch, and passing only the top retrieved chunks into the answer-generation prompt. Chunk size, overlap, and the number of retrieved results (top-k) directly affect prompt length and cost, so these settings should be estimated against real documents and user queries before production deployment. Reranking retrieved chunks can improve context quality, allowing fewer chunks to be sent to the language model without sacrificing answer accuracy. Idempotency safeguards are also critical during document indexing, as naive retries can create duplicate chunk records that distort retrieval results.