Saturday, 7 November 2026
Molecular Structure Visualization in Python Using RDKit
Python Coding November 07, 2026 Python No comments
Molecular Structure Visualization in Python Using RDKit
Introduction
Python is widely used in scientific computing, artificial intelligence, machine learning, and data science. But did you know that Python can also help you visualize chemical molecules and explore their structures?
One of the most powerful libraries for this purpose is RDKit.
RDKit is an open-source cheminformatics toolkit that allows developers, researchers, and computational chemists to work with molecular structures, chemical fingerprints, molecular descriptors, and chemical data.
With just a few lines of Python code, you can convert a chemical representation into a visual molecular structure.
In this tutorial, we will learn how to install RDKit, understand SMILES notation, and generate a molecular structure image using Python.
What Is RDKit?
RDKit is an open-source software toolkit designed for cheminformatics and molecular data processing.
It provides Python APIs for working with chemical information and molecular structures.
Key Features of RDKit
Molecular Visualization: Generate 2D molecular structure diagrams.
SMILES Processing: Convert SMILES strings into molecular objects.
Molecular Descriptors: Calculate molecular properties and descriptors.
Chemical Fingerprints: Generate molecular fingerprints for similarity analysis.
Substructure Searching: Find specific chemical patterns inside molecules.
Molecular Manipulation: Create, modify, and analyze chemical structures.
RDKit is especially useful in computational chemistry, pharmaceutical research, cheminformatics, and AI-driven drug discovery.
1. Install RDKit
First, install RDKit using pip.
%pip install rdkitIf you are working in Jupyter Notebook, execute this command in a notebook cell.
2. Import Required Libraries
Next, import the required modules.
from rdkit import Chem
from rdkit.Chem import DrawUnderstanding the imports:
Chem: Provides tools for creating and manipulating molecular structures.Draw: Provides functionality for generating molecular structure images.
3. Create a Molecular Structure Using SMILES
SMILES stands for Simplified Molecular Input Line Entry System.
It is a text-based notation used to represent chemical structures.
Instead of manually drawing a molecule, we can describe its atoms, bonds, and connectivity using a SMILES string.
Let's use the following SMILES representation:
smiles = "CC(=O)OC1=CC=CC=C1C(=O)O"This represents Aspirin (Acetylsalicylic Acid).
Now convert the SMILES string into an RDKit molecular object.
mol = Chem.MolFromSmiles(smiles)The MolFromSmiles() function parses the SMILES string and creates a molecular object.
4. Visualize the Molecular Structure
RDKit provides MolToImage() to generate a 2D molecular diagram.
from IPython.display import display
display(
Draw.MolToImage(
mol,
size=(450, 300)
)
)This generates a visual representation of the aspirin molecule.
The diagram displays:
Carbon atoms and their connectivity
Oxygen atoms
Single and double chemical bonds
The benzene ring
Functional groups
You can change the image dimensions using the size parameter.
5. Complete Python Code
Here is the complete implementation in one place:
from rdkit import Chem
from rdkit.Chem import Draw
from IPython.display import display
# SMILES representation of Aspirin
smiles = "CC(=O)OC1=CC=CC=C1C(=O)O"
# Convert SMILES into a molecular object
mol = Chem.MolFromSmiles(smiles)
# Check whether the molecule was parsed
if mol is not None:
display(Draw.MolToImage(mol, size=(450, 300)))
else:
print("Invalid SMILES string")This code can be executed directly in Jupyter Notebook.
6. Important RDKit Functions
Here are some useful RDKit functions worth exploring:
| Function | Purpose |
|---|---|
Chem.MolFromSmiles() | Create a molecule from SMILES |
Chem.MolToSmiles() | Convert a molecule into SMILES |
Draw.MolToImage() | Generate a 2D molecular image |
Chem.AddHs() | Add explicit hydrogen atoms |
Chem.RemoveHs() | Remove explicit hydrogen atoms |
Chem.MolFromMolBlock() | Read a molecule from a MolBlock |
Chem.FindMolChiralCenters() | Identify chiral centers |
7. Real-World Applications of RDKit
RDKit is useful across several scientific and technological fields.
Drug Discovery
Researchers use molecular representations and descriptors to investigate potential drug candidates.
Computational Chemistry
Chemists can process and analyze molecular structures programmatically.
Molecular Similarity
Chemical fingerprints can help compare molecules and identify structurally similar compounds.
Machine Learning
Molecular descriptors and fingerprints can be used as input features for machine learning models.
Artificial Intelligence in Chemistry
RDKit can be integrated into AI pipelines for molecular property prediction, chemical data processing, and generative molecular research.
8. Why Python Developers Should Learn RDKit
Python is not limited to web development, automation, or data analysis.
Its scientific ecosystem allows developers to work in specialized fields such as chemistry, biology, healthcare, and pharmaceutical research.
Learning RDKit introduces developers to:
Scientific Python programming
Molecular data processing
Chemical structure visualization
Computational chemistry
Molecular machine learning
AI-assisted drug discovery
It is an excellent library for developers interested in combining Python with scientific research.
Conclusion
RDKit demonstrates how powerful Python can be beyond traditional programming applications.
With only a few lines of code, we can convert a SMILES string into a molecular object and generate a 2D chemical structure diagram.
Whether you are a Python developer, data scientist, computational chemist, or AI researcher, RDKit is a valuable tool to explore.
Start experimenting with molecular structures and discover how Python connects programming with the world of chemistry!
Explore more Python libraries and scientific computing resources at CLCODING.
Python Coding Challenge - Question with Answer (ID 071126)
Explanation:
Python Turtle — The Hypnotic Rainbow Vortex
Python Developer November 07, 2026 Python Turtle No comments
Code:
import turtle
import time
import colorsys
s = turtle.Screen()
s.setup(750, 750)
s.bgcolor("black")
s.title("Rainbow Hypnotic Vortex")
s.tracer(0)
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
t.pensize(2)
for i in range(180):
t.pencolor(colorsys.hsv_to_rgb(i / 180, 1, 1))
t.penup()
t.goto(0, 0)
t.setheading(i * 7)
t.pendown()
length = 80 + i * 1.8
for _ in range(2):
t.forward(length)
t.circle(35 + i * 0.15, 90)
s.update()
time.sleep(0.025)
turtle.done()
Explanation:
Friday, 6 November 2026
Generative AI and Large Language Models
Python Developer November 06, 2026 Generative AI No comments
Generative AI and Large Language Models — Complete Course Review
Introduction
Generative Artificial Intelligence is transforming the way people create content, develop software, analyze information, and interact with technology. From ChatGPT and image generation tools to intelligent assistants and multimodal applications, generative AI is becoming an essential part of modern technology.
Generative AI and Large Language Models is a Coursera course designed to introduce learners to the foundations, architectures, and practical applications of modern generative AI systems.
The course explores different generative model architectures, including Generative Adversarial Networks (GANs), Variational Autoencoders (VAEs), Transformers, and Diffusion Models. It also introduces practical development using OpenAI, Hugging Face, PyTorch, Streamlit, and MLflow.
With five modules and approximately 30 hours of estimated learning time, this course provides a broad learning path covering LLMs, prompt engineering, fine-tuning, Retrieval Augmented Generation (RAG), image generation, and multimodal AI.
What Makes This Course Special?
Many introductory AI courses focus primarily on using existing AI tools. This course goes further by exploring the technologies and architectures behind generative models.
Learners study how different generative models work, how transformers process language, and how pretrained models can be adapted for specific applications.
Another important feature is its practical approach. The curriculum includes programming labs involving Hugging Face, PyTorch, FAISS, Stable Diffusion, CLIP, BLIP, and Whisper.
It also introduces deployment using Streamlit and MLflow, helping learners understand how generative AI models can be transformed into usable applications.
Key Topics Covered
1. Introduction to Generative AI
The first module introduces the fundamentals of Generative Artificial Intelligence and explains how generative models differ from traditional discriminative models.
Learners explore the evolution of generative technologies and understand how AI systems can create new content rather than simply classify existing information.
Important topics include:
Introduction to Generative AI
Discriminative and generative models
Generative Adversarial Networks
Variational Autoencoders
Autoregressive models
Diffusion models
Large Language Models
Vision-Language Models
Responsible AI and ethical considerations
The module also includes practical exercises involving simple generative models and VAEs.
2. Large Language Models and Transformer Architecture
Transformers are the foundation of many modern Large Language Models.
This module explores how transformer architectures process information and generate text. Learners examine self-attention, multi-head attention, and the components responsible for capturing relationships between words and tokens.
Key topics include:
Evolution from RNNs to Transformers
Transformer architecture
Self-attention mechanisms
Multi-head attention
Feedforward networks
Text generation
Temperature, Top-k, and Top-p sampling
Prompt engineering
LLM APIs
Fine-tuning with Hugging Face
The module also introduces Parameter-Efficient Fine-Tuning (PEFT) and LoRA, helping learners understand how pretrained language models can be adapted without updating every model parameter.
3. Hands-on Applications of Large Language Models
This module moves from understanding LLM architectures to developing practical applications.
Learners explore how language models can be connected with external information, structured outputs, and application interfaces.
Important topics include:
Retrieval Augmented Generation (RAG): Learn how external knowledge sources can be connected to LLMs to improve the relevance and contextual accuracy of responses.
Vector Embeddings and Search: Explore how text can be represented as numerical embeddings and retrieved using similarity search with FAISS.
Structured Outputs: Understand how to guide LLMs to generate responses in structured formats suitable for applications.
Function Calling and Tool Simulation: Explore how language models can interact with external functions and tools.
AI Agents: Learn the basic concepts behind systems that combine language models with tools and multi-step workflows.
Model Deployment: Introduce Streamlit and MLflow for developing and deploying text-generation applications.
The practical labs include implementing a simple RAG pipeline and deploying a text-generation model.
4. Diffusion Models and Image Generation
Diffusion Models have become an important technology in modern generative AI, particularly for image generation.
This module explains how these models gradually transform random noise into meaningful visual content through an iterative denoising process.
Topics include:
Fundamentals of diffusion models
Forward and reverse diffusion processes
Image generation using Stable Diffusion
Latent diffusion concepts
Text-to-image generation
Comparing GANs, VAEs, and diffusion models
Implementing diffusion experiments with PyTorch
Learners also explore practical image-generation exercises using Stable Diffusion.
This section is useful for understanding the technology behind modern AI image-generation applications.
5. Multimodal Generative AI
Modern AI systems are increasingly capable of processing multiple types of information, including text, images, and audio.
This module introduces multimodal AI and explores how different modalities can be combined within intelligent applications.
Important topics include:
Vision-Language Models: Explore models that connect visual information with natural language.
CLIP: Understand how text and image representations can be aligned for tasks such as zero-shot image classification.
BLIP: Explore image captioning and vision-language understanding.
Whisper: Learn how speech recognition systems convert audio into text.
Text-to-Speech: Understand how generated text can be converted into spoken audio.
The module concludes with a capstone project in which learners build their own Generative AI assistant using RAG, LLMs, and multimodal input.
Practical Skills You Can Develop
After completing the course and practising its programming labs, learners can develop experience in:
Understanding the fundamentals of generative AI.
Explaining GANs, VAEs, Transformers, and diffusion models.
Working with pretrained Large Language Models.
Understanding attention mechanisms and transformer architectures.
Performing lightweight LLM fine-tuning using LoRA.
Building RAG applications using FAISS and Hugging Face.
Connecting LLMs with APIs and external tools.
Developing text-generation applications with Streamlit.
Managing model workflows using MLflow.
Generating images using Stable Diffusion.
Exploring vision-language models using CLIP and BLIP.
Performing speech recognition using Whisper.
Developing multimodal AI assistants.
Who Should Take This Course?
Python Developers: Programmers interested in moving into Generative AI and LLM application development.
Machine Learning Students: Learners who want to understand the architectures behind modern generative models.
Data Scientists: Professionals interested in fine-tuning language models, building RAG systems, and working with multimodal data.
AI Engineers: Developers who want practical exposure to LLM applications, deployment, and multimodal AI.
Generative AI Enthusiasts: Learners who want to explore the technologies behind text generation, image generation, and AI assistants.
The course is listed at an intermediate level. Basic programming and familiarity with machine learning concepts will make the practical exercises easier to follow.
Strengths of the Course
Broad generative AI coverage: Explores GANs, VAEs, Transformers, diffusion models, and multimodal architectures.
Practical programming labs: Provides opportunities to experiment with modern AI tools and frameworks.
LLM development: Covers prompt engineering, APIs, and lightweight fine-tuning.
RAG implementation: Introduces embeddings, vector search, and external knowledge integration.
Image generation: Includes practical work with diffusion models and Stable Diffusion.
Multimodal AI: Covers image, text, and audio-based applications.
Deployment experience: Introduces Streamlit and MLflow for application development and deployment.
Capstone project: Combines RAG, LLMs, and multimodal input in a Generative AI assistant.
Limitations to Consider
This course covers several major areas of Generative AI, so learners should expect to spend additional time experimenting with the programming labs.
The curriculum provides an introduction to many architectures and tools rather than deep specialization in every individual technology.
Some practical exercises may require access to external model services, APIs, or computational resources. Learners should check the requirements and potential usage costs before starting those activities.
The course is also not a complete deep learning mathematics or advanced model-training program. Learners interested in training large foundation models from scratch will need more specialized resources.
Join Now: Generative AI and Large Language Models
Final Verdict
Generative AI and Large Language Models is a comprehensive introductory-to-intermediate learning resource for anyone interested in understanding modern generative AI technologies.
Its biggest strength is the variety of topics covered within one course. Learners explore traditional generative architectures, transformer-based language models, RAG systems, diffusion models, and multimodal AI.
The practical labs make the curriculum particularly interesting because they provide exposure to tools such as Hugging Face, PyTorch, FAISS, Stable Diffusion, CLIP, BLIP, Whisper, Streamlit, and MLflow.
For the best learning experience, complete the exercises independently and build additional projects such as a document-based AI assistant, an image-captioning application, or a speech-to-text chatbot.
๐ Python Pattern Challenge — Day 42
Python Developer November 06, 2026 Python Pattern Challenge No comments
๐ Python Pattern Challenge — Day 42 | Cyclic Number Square Pattern
Welcome to Day 42 of the Python Pattern Challenge! ๐
Today, we're creating a beautiful Cyclic Number Square Pattern using Python. This pattern looks like a simple number square, but there's an interesting twist: every new row starts with the next number and continues the sequence until it reaches 5, then starts again from 1.
This challenge is perfect for practicing loops, nested loops, the modulo operator, and mathematical logic.
๐ฏ Today's Challenge
Write a Python program to print the following pattern:
๐ป Python Solution
n = 5 for i in range(n): for j in range(n): print((i + j) % n + 1, end=" ") print()
๐ง How It Works
1. Creating the rows
for i in range(n):The outer loop controls the number of rows. Since n = 5, it generates five rows.
2. Creating the columns
for j in range(n):The inner loop generates five numbers in every row.
3. Understanding the modulo operator
(i + j) % n + 1This is the main logic behind the pattern.
i + j increases the number in each column.
% n keeps the result within the range of 0 to 4.
+ 1 converts the result into numbers from 1 to 5.
4. Printing numbers in the same row
print((i + j) % n + 1, end=" ")The end=" " argument prints numbers horizontally with spaces instead of moving to a new line.
5. Moving to the next row
print()This moves the cursor to the next line after completing each row.
๐ Challenge Yourself
Increase the square size to 7 × 7.
Replace numbers with alphabets.
Create a reverse cyclic number pattern.
Try solving the pattern without using the modulo operator.
Take the square size as input from the user.
๐ก Key Takeaway
The modulo operator (%) is extremely useful for creating repeating sequences and cyclic patterns in Python. Understanding this concept will also help you solve more advanced programming problems.
42 Days. 42 Patterns. Stronger Python Logic. ๐๐ฅ
Learn • Practice • Grow with CLCODING
Artificial Intelligence for Business + LLM Prize [2026]
AI for Business — Learn How Artificial Intelligence Transforms Modern Businesses
Introduction
Artificial Intelligence is changing the way businesses operate, make decisions, communicate with customers, and manage daily activities. From automating repetitive tasks to analyzing customer behavior and improving financial operations, AI is becoming an important part of modern business strategy.
AI for Business is a Udemy course designed to help learners understand how Artificial Intelligence can be applied across different business functions. Created by 101 Blockchains, the course introduces AI fundamentals and explores practical applications in marketing, sales, human resources, operations, supply chain management, finance, and accounting.
Rather than concentrating on programming or building machine learning models, the course focuses on understanding business opportunities, selecting suitable AI tools, and preparing organizations for AI adoption.
With approximately three hours of video content, it provides a concise introduction for professionals, entrepreneurs, managers, and anyone interested in understanding the business impact of Artificial Intelligence.
What Makes This Course Special?
Many AI courses focus on technical concepts such as neural networks, machine learning algorithms, and Python programming. This course takes a business-oriented approach.
It explains how organizations can use AI to improve productivity, understand customers, optimize workflows, and support better decision-making.
The curriculum also includes demonstrations of tools such as Google Gemini, ChatGPT for Business, and other AI-powered platforms. These examples help learners connect AI concepts with practical business scenarios.
Another important aspect is its focus on AI implementation strategy. Businesses need more than access to AI tools; they must identify suitable use cases, prepare their teams, and understand the risks associated with adopting new technologies.
Key Topics Covered
1. Introduction to AI in Business
The course begins with the fundamentals of Artificial Intelligence and its growing importance in business environments.
Learners explore how AI works, the benefits it offers, and how organizations can use intelligent technologies to improve their operations.
Topics include AI fundamentals, business applications, productivity improvements, and AI-driven decision-making.
This section helps beginners understand why AI is becoming an important business capability.
2. Implementing AI in Business
Understanding AI is only the first step. Organizations also need a strategy for introducing it into their existing workflows.
This section explores how businesses can prepare for AI integration and identify tools that match their requirements.
Learners examine AI implementation strategies, business readiness, and practical demonstrations involving ChatGPT for Business and other AI platforms.
The goal is to understand how businesses can move from experimenting with AI tools toward using them as part of their regular operations.
3. AI for Marketing and Sales
Marketing and sales are among the areas where AI can provide significant value.
AI-powered tools can analyze customer behavior, identify potential audiences, support content creation, and improve marketing campaigns.
The course explores:
AI-driven customer insights
Customer targeting and segmentation
AI sales tools
Marketing strategy optimization
Automated sales workflows
Customer engagement
These applications help businesses understand their audiences and create more informed marketing strategies.
4. AI Applications in Human Resources
Human Resources departments handle several processes that involve large amounts of information and repetitive administrative work.
AI can support recruitment, candidate screening, employee engagement, and performance management.
This section explores how AI can assist with talent acquisition, resume filtering, employee development, and workforce management.
It also introduces the importance of using AI responsibly in HR, where fairness, transparency, and human judgment remain essential.
5. AI for Operations and Supply Chain Management
Business operations involve managing resources, maintaining equipment, monitoring quality, and coordinating supply chains.
AI can help organizations identify inefficiencies and improve operational planning.
The course introduces applications such as predictive maintenance, quality control, supply chain optimization, and process improvement.
For example, predictive maintenance can help businesses identify potential equipment problems before they cause unexpected failures.
These concepts demonstrate how AI can support more efficient and reliable business operations.
6. AI for Finance and Accounting
Finance and accounting departments can benefit from AI-powered automation and data analysis.
The course explores how AI can support financial workflows, identify unusual transactions, and assist with risk management.
Important topics include:
Financial process automation
Fraud detection
Risk management
Personal finance applications
AI-supported financial analysis
Accounting workflow optimization
These applications can help reduce repetitive work and provide useful insights for financial decision-making.
7. The Future of AI in Business
Artificial Intelligence continues to evolve, creating new opportunities and challenges for organizations.
The final module explores emerging AI developments and their potential impact on businesses and society.
Learners examine the importance of developing an AI strategy and understanding how organizations can adapt to technological changes.
This section encourages businesses to think beyond individual tools and consider how AI may influence their long-term operations and competitiveness.
Practical Skills You Can Develop
After completing the course, learners should have a better understanding of how to:
Explain the fundamentals of Artificial Intelligence.
Identify opportunities for AI adoption in businesses.
Understand how to prepare organizations for AI integration.
Explore AI applications in marketing and sales.
Identify potential uses of AI in recruitment and HR management.
Understand AI applications in finance and accounting.
Explore predictive maintenance and supply chain optimization.
Evaluate business needs when selecting AI tools.
Understand the importance of AI strategy and responsible implementation.
Who Should Take This Course?
Business owners and entrepreneurs: People interested in using AI to improve productivity, customer engagement, and business operations.
Managers and team leaders: Professionals who want to understand how AI can support their teams and business processes.
Marketing and sales professionals: Learners interested in AI-powered customer insights, targeting, content creation, and sales automation.
HR professionals: People exploring AI applications in recruitment, performance management, and employee engagement.
Finance professionals: Learners interested in financial automation, fraud detection, and AI-supported analysis.
AI beginners: Anyone who wants to understand how Artificial Intelligence can be applied in business without starting with programming or advanced mathematics.
No specific technical prerequisites are required. Basic familiarity with business operations is helpful but not essential.
Strengths of the Course
Business-focused curriculum: Concentrates on real organizational applications rather than programming theory.
Multiple business functions: Covers marketing, sales, HR, operations, supply chain, finance, and accounting.
Practical demonstrations: Introduces examples involving tools such as ChatGPT and Google Gemini.
Beginner-friendly approach: Does not require prior AI or programming experience.
AI implementation strategy: Helps learners understand business readiness and the process of adopting AI.
Concise learning format: Its relatively short duration makes it suitable for busy professionals.
Limitations to Consider
This course provides a business-level understanding of AI rather than technical training in machine learning or deep learning.
Learners who want to build AI applications using Python, TensorFlow, PyTorch, or scikit-learn will need additional programming-focused courses.
The demonstrations introduce selected AI tools, but they do not provide an extensive technical tutorial on every platform. Since AI products change frequently, learners should also explore their latest features independently.
Additionally, successful AI implementation requires more than choosing a tool. Businesses must consider data privacy, security, employee training, ethical concerns, and the reliability of AI-generated results.
Join Now: Artificial Intelligence for Business + LLM Prize [2026]
Final Verdict
AI for Business is a useful introductory course for anyone who wants to understand how Artificial Intelligence can transform different areas of an organization.
Its biggest strength is its broad coverage of business applications, including marketing, sales, human resources, operations, supply chain management, finance, and accounting.
The course is particularly suitable for non-technical professionals who want to understand AI opportunities without learning programming or building machine learning models.
For learners interested in developing deeper technical skills, a good next step would be to explore Python-based AI automation, machine learning, and Generative AI application development.
Python Coding Challenge - Question with Answer (ID 061126)
Explanation:
Books: 100 Days of Math with Python
Thursday, 5 November 2026
Python Coding Challenge - Question with Answer (ID 051126)
Explanation:
Books: AUTOMATING EXCEL WITH PYTHON
Wednesday, 4 November 2026
Python Coding challenge - Day 1304| What is the output of the following Python Code?
Python Developer November 04, 2026 Python Coding Challenge No comments
Code Explanation:
Books: 900 Days Python Coding Challenges with Explanation
Python Coding challenge - Day 1303| What is the output of the following Python Code?
Python Developer November 04, 2026 Python Coding Challenge No comments
Code Explanation:
Flatten Nested Lists in Python 3.15 Using * – A Cleaner Way to Write Python Code
Python Coding November 04, 2026 Python, Python Tips No comments
Flatten Nested Lists in Python 3.15 Using * – A Cleaner Way to Write Python Code
Python 3.15 introduces an interesting improvement to Python comprehensions: unpacking directly inside list comprehensions using the * operator.
If you frequently work with nested lists, this new syntax provides a cleaner alternative to traditional nested list comprehensions.
Let's understand how it works with a simple example.
1. Understanding Nested Lists
A nested list is a list that contains other lists as its elements.
Consider the following example:
daily_weather = [
["☀️", "☁️"],
["๐ง️"],
["☀️", "๐ฉ️"]
]
print(daily_weather)Output:
[['☀️', '☁️'], ['๐ง️'], ['☀️', '๐ฉ️']]Here, we have three separate lists containing weather conditions.
What if we want to combine all these elements into one single list?
This process is called flattening a list.
2. Traditional Approach (Before Python 3.15)
Before Python 3.15, we commonly used nested list comprehensions.
daily_weather = [
["☀️", "☁️"],
["๐ง️"],
["☀️", "๐ฉ️"]
]
result = [
weather
for day in daily_weather
for weather in day
]
print(result)Output:
['☀️', '☁️', '๐ง️', '☀️', '๐ฉ️']How does it work?
The first
forloop iterates through each inner list.The second
forloop accesses every element inside that list.Each element is added to the resulting list.
This approach works perfectly, but Python 3.15 introduces a more compact alternative.
3. Python 3.15: Flatten Lists Using *
Python 3.15 introduces unpacking in comprehensions through PEP 798.
Now, you can use the * operator directly inside a list comprehension.
daily_weather = [
["☀️", "☁️"],
["๐ง️"],
["☀️", "๐ฉ️"]
]
result = [*day for day in daily_weather]
print(result)Output:
['☀️', '☁️', '๐ง️', '☀️', '๐ฉ️']That's it!
The * operator unpacks each inner iterable, adding its individual elements to the resulting list.
4. Before vs. Python 3.15
| Traditional approach | Python 3.15 |
|---|---|
[x for d in data for x in d] | [*d for d in data] |
| Nested iteration | Iterable unpacking |
| More explicit | More compact |
Both approaches produce the same flattened list for this example.
5. More Examples
The new syntax works with other iterable types too.
Example 1: Flatten a list of numbers
numbers = [
[1, 2, 3],
[4, 5],
[6, 7, 8]
]
result = [*group for group in numbers]
print(result)Output:
[1, 2, 3, 4, 5, 6, 7, 8]Example 2: Flatten a list containing strings
words = [
["Python", "Java"],
["C++", "JavaScript"]
]
result = [*group for group in words]
print(result)Output:
['Python', 'Java', 'C++', 'JavaScript']Example 3: Flatten a list containing empty lists
data = [
[10, 20],
[],
[30, 40]
]
result = [*group for group in data]
print(result)Output:
[10, 20, 30, 40]Empty inner iterables simply contribute no elements.
6. Important Things to Remember
This syntax was introduced in Python 3.15 through PEP 798.
It works with list and set comprehensions, dictionary comprehensions, and generator expressions.
The
*operator unpacks an iterable into individual elements.It flattens one level of nesting at a time.
It does not recursively flatten deeply nested lists.
Python 3.14 and earlier do not support this new comprehension syntax.
Important: This is not a recursive flattening solution. If your list contains multiple levels of nested lists, you will need a recursive function or another suitable approach.
7. Conclusion
Python continues to evolve with features that make code more expressive and easier to read.
The new unpacking syntax in Python 3.15 provides another way to flatten nested lists without writing multiple for clauses.
Traditional approach:
[x for group in data for x in group]Python 3.15 approach:
[*group for group in data]Both are useful, but the new syntax gives developers another compact option.
Keep learning, keep coding!
Follow CLCODING for more Python tutorials, coding challenges, and programming updates.
Frequently Asked Questions
Q1. What is list flattening in Python?
List flattening is the process of converting a list containing other lists into a single list containing their individual elements.
Q2. Which Python version supports unpacking in comprehensions?
Python 3.15 introduced this feature through PEP 798.
Q3. Does [*group for group in data] flatten multiple nested levels?
No. It flattens only one level. Deeply nested lists require a recursive or multi-level approach.
Q4. Is the traditional nested list comprehension still supported?
Yes. The traditional syntax remains valid and works in earlier Python versions.
Q5. Is the new syntax faster?
It provides a more concise way to express flattening. Do not assume it is faster in every situation; benchmark both approaches for performance-sensitive applications.
Python Coding Challenge - Question with Answer (ID 041126)
Explanation:
Books: 100 Python Automation Projects for Smart Developers
Tuesday, 3 November 2026
๐ Python Pattern Challenge — Day 40
Python Developer November 03, 2026 Python Coding Challenge No comments
๐ Python Pattern Challenge — Day 40 | Number Wave Pattern
Welcome to Day 40 of the Python Pattern Challenge! ๐
Today, we're creating an interesting Number Wave Pattern using Python. This pattern starts with a complete number sequence, gradually reduces the numbers in each row, and then expands again to create a symmetrical wave-like design.
It's a simple but effective challenge to improve your understanding of loops, number sequences, spacing, and pattern-building logic.
๐ฏ Today's Challenge
Write a Python program to print exactly the following pattern:
๐ป Python Solution
n = 5 for i in range(1, n + 1): print(" " * (i - 1), end="") print(*range(i, n + 1)) for i in range(n - 1, 0, -1): print(" " * (i - 1), end="") print(*range(i, n + 1))
๐ง How It Works
1. Creating the upper section
for i in range(1, n + 1):This loop generates the first five rows, starting from 1 and increasing the starting number in each row.
2. Managing the spacing
print(" " * (i - 1), end="")This adds leading spaces to shift each row toward the center.
3. Printing the number sequence
print(*range(i, n + 1))The range() function generates numbers from the current value of i up to 5.
4. Creating the lower section
for i in range(n - 1, 0, -1):This loop reverses the process, gradually restoring the complete number sequence.
๐ Challenge Yourself
Increase the pattern size to 7.
Replace numbers with alphabets.
Create an inverted version of this pattern.
Try implementing the same pattern using a while loop.
Take the maximum number as input from the user.
The best way to improve your Python logic is to practice small challenges and experiment with different patterns.
41 Days. 41 Patterns. Stronger Python Logic. ๐๐ฅ
Learn • Practice • Grow with CLCODING
Popular Posts
-
Deep learning is often presented as a combination of Python programming, neural networks, datasets, and powerful computing systems. Howeve...
-
Python for AI Bootcamp 2026: 15-Day Complete Syllabus from Python Basics to Generative AI Artificial Intelligence is transforming the way ...
-
Machine learning has become one of the most influential fields in computer science, powering technologies such as recommendation systems, ...
-
Machine Learning is best understood when theory is combined with practical implementation. Instead of learning algorithms only through def...
-
๐ Python Pattern Challenge — Day 39 | Hollow Hourglass Star Pattern Welcome to Day 39 of the Python Pattern Challenge! ๐ Today, we'...
-
What you'll learn Understand the importance of cybersecurity practices and their impact for organizations. Identify common risks, thre...
-
Explanation: Step 1: Creating a Set x = {1, 2, 3} Here, we create a set named x containing three elements: {1, 2, 3} Step 2: Understanding...
-
Pydantic Settings: Manage Python Application Configuration Like a Pro SEO Title: Pydantic Settings in Python: Manage Environment Variable...
-
Explanation: 1. Creating a Frozenset x = frozenset([1, 2, 2, 3]) - frozenset() creates an immutable set. - It automatically removes duplic...
-
Explanation: Step 1: Understanding the any() Function The any() function checks whether at least one element in an iterable evaluates to T...
.png)

.png)





.png)
.png)
.png)


.png)
.png)
