Text to Python

Python List Converter

Turn pasted values into Python.

Build the Python list

Python List Converter

0 items / 0 unique
Input Text
0 characters Ctrl+Enter to convert - Drag and drop .txt
Split Input By
Cleaning Options
Output
Output Format
Python options
Customization
Output 0 unique Output
// Your converted output will appear here.
Equivalent code
Paste text and click Convert Text, or use Ctrl+Enter.
Your text stays private. All conversion happens locally in your browser using JavaScript. Nothing is uploaded to any server.

Choose a list, a tuple or a set, and decide whether numbers and booleans become real Python literals — True, False and None, not the lowercase JSON spellings.

How It Works

How to use the Python List Converter

  1. Paste your values

    One per line by default; switch the delimiter for comma or tab separated sources.

  2. Pick the container

    List for ordered, mutable data. Tuple when it must not change — a dict key, or a function returning fixed values. Set to drop duplicates and lose ordering.

  3. Choose how values are typed

    Strings quotes everything. Numbers emits bare numeric literals. Auto also converts true/false to True/False and null, none or nil to None.

Examples

Python List Converter examples

A Python list

Input

London
Paris
Tokyo

Output

cities = [
  "London",
  "Paris",
  "Tokyo"
]

A tuple, including the single-element case

Input

London

Output

cities = ("London",)

A one-element tuple needs its trailing comma, or the parentheses are just grouping. The tool adds it.

Python literals with type detection on

Input

1
2.5
true
null
name

Output

values = [
  1,
  2.5,
  True,
  None,
  "name"
]

Auto mode maps true to True and null to None — the Python spellings, not the JSON ones.

Notes

Working with text to array python

List, tuple, or set

A list is mutable and ordered. A tuple is immutable and hashable, so it can be a dictionary key or a set member. A set deduplicates and discards order — wrong for anything positional, and exactly right for membership tests, where `in` is O(1) against a set and O(n) against a list.

The single-element tuple trap

("London") is not a tuple; it is a string in parentheses. Only the trailing comma makes it one: ("London",). This tool emits that comma automatically, which is the case people most often get wrong by hand.

Python is not JSON

Python writes True, False and None where JSON writes true, false and null. Pasting JSON straight into a .py file fails on exactly those three tokens. Auto mode maps them for you — which is also why json.loads() exists rather than eval().

FAQ

Python List Converter FAQs

Python List Converter

Turn pasted values into Python. Choose a list, a tuple or a set, and decide whether numbers and booleans become real Python literals — True, False and None, not the lowercase JSON spellings.