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 1 · 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

One model. Six levels of effort.

MGS AI 1 can answer instantly or think for minutes, and it can search the web at every level. Higher effort thinks longer and counts more toward your limit. Free includes Low and Medium; every paid plan includes all six.

  1. Low

    Answers right away and can search the web.

    Included in Free

  2. Medium

    Thinks briefly, searches and reads pages.

    Included in Free

  3. High

    Thinks longer, searches and reads pages.

    From Basic

  4. xHigh

    Thinks deeply and runs code to check its work.

    From Basic

  5. Max

    Works out several drafts, then one combined answer.

    From Basic

  6. Ultra

    Four independent attempts, checked and merged.

    From Basic

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

Low and Medium effort15 units per 5 h

Basic

€5/mo

All 6 efforts60 units per 5 h

Plus

€10/mo

All 6 efforts150 units per 5 h

Pro

€20/mo

All 6 efforts400 units per 5 h

Pro+

€50/mo

All 6 efforts1,200 units per 5 h

MAX

€100/mo

All 6 efforts3,000 units per 5 h

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