Paste the error. Get the fix.
Why does last([]) crash with IndexError: list index out of range?
last() reads xs[len(xs)], one past the end 1. Return xs[-1] and guard the empty list:
def last(xs):
if not xs:
raise ValueError("last() of an empty list")
return xs[-1]
Built for the bug you can't find.
Reads your code and your stack traces
Attach files or paste a trace. MGS AI finds the cause, explains it and writes the fix.
def last(xs):
- return xs[len(xs)]
+ if not xs:
+ raise ValueError("last() of an empty list")
+ return xs[-1]
Searches the web, shows its sources
Answers about libraries and APIs come with links you can check.
- 1
Built-in Types: common sequence operationsdocs.python.org
- 2
IndexError: list index out of rangestackoverflow.com
- 3
An Informal Introduction to Python: listsdocs.python.org
Thinks before it answers
Open the thinking to see how it got there, or leave it folded away.
Thought for 14 s
Runs code to check itself
From xHigh up, it can test an answer in a Python sandbox.
$ pytest test_last.py
3 passed in 0.04sMakes images, too
Icons, diagrams and illustrations, right in the chat. Every image is saved to your library and marked as AI-made.

Six modes. You choose how hard it thinks.
Higher modes think longer, use more tools and count more toward your limit.
MGS AI Low
Fastest replies, no extended thinking.
Included in Free
MGS AI Medium
Thinks briefly and can search the web.
From Basic
MGS AI High
Thinks longer, searches and reads pages.
From Plus
MGS AI xHigh
Deep thinking and can run code.
From Pro
MGS AI Max
Several drafts, then one combined answer.
From Pro+
MGS AI Ultra
Four independent attempts plus a synthesis.
From the MAX plan
Your code stays yours.
MGS AI is made by Max's Global Solutions in Latvia. We store as little as we can and you control all of it.
Read the privacy policyEncrypted storage in the EU
Uploads and images live in an encrypted bucket in Stockholm. Links to them expire after 5 minutes.
No message logs
The AI engine records request metadata such as token counts, never your messages or files.
Export or delete anytime
Download all your data as JSON, or delete your account and its files in settings.
Essential cookies only
No ads, no tracking pixels and no analytics cookies.
Start free. Upgrade when you need more.
Free
€0/mo
Up to MGS AI Low
Basic
€5/mo
Up to MGS AI Medium
Plus
€10/mo
Up to MGS AI High
Pro
€20/mo
Up to MGS AI xHigh
Pro+
€50/mo
Up to MGS AI Max
MAX
€100/mo
Up to MGS AI Ultra
Monthly, in euros, through PayPal. Cancel anytime.
See pricing