Paste the error. Get the fix.

MGS AI is a coding and debugging specialist that also chats, searches the web and makes images.

Fix IndexError in last()MGS AI High
utils.py

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:

Python
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.

Diff
 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. 1Built-in Types: common sequence operations
  2. 2IndexError: list index out of range
  3. 3An Informal Introduction to Python: lists

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.04s

Makes images, too

Icons, diagrams and illustrations, right in the chat. Every image is saved to your library and marked as AI-made.

A small orange robot reaching for a laptop keyboard on a sunlit wooden desk
Made with MGS AI

Six modes. You choose how hard it thinks.

Higher modes think longer, use more tools and count more toward your limit.

  1. MGS AI Low

    Fastest replies, no extended thinking.

    Included in Free

  2. MGS AI Medium

    Thinks briefly and can search the web.

    From Basic

  3. MGS AI High

    Thinks longer, searches and reads pages.

    From Plus

  4. MGS AI xHigh

    Deep thinking and can run code.

    From Pro

  5. MGS AI Max

    Several drafts, then one combined answer.

    From Pro+

  6. 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 policy

Encrypted 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

Try it on the bug you're stuck on.

No card needed for the Free plan.

Start free