Python Forum
Code runs as pure python but not jupyter notebook
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code runs as pure python but not jupyter notebook
#1
Hello to the forum. As you can tell from the title, I am just learning python, and its use as a jupyter notbook.

I have this cell with a few lines of code that seems to run fine, under pycharm, when I use it in a file type of pure python. But when I use that same code in a file type ipynb, I get an "invalid syntax" error.

def quicksort(arr):
    if len(arr) <= 1:
        return arr
    pivot = arr[len(arr) // 2]
    left = [x for x in arr if x < pivot]
    middle = [x for x in arr if x == pivot]
    right = [x for x in arr if x > pivot]
    return quicksort(left) + middle + quicksort(right)

print quicksort([3, 6, 8, 10, 1, 2, 1])


Here is the error:

print quicksort([3, 6, 8, 10, 1, 2, 1])
syntax error



Thank You
Tom
Reply


Messages In This Thread
Code runs as pure python but not jupyter notebook - by miner_tom - Aug-22-2018, 04:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 1,052 Nov-15-2023, 06:56 PM
Last Post: jst
  Navigating file directories and paths inside Jupyter Notebook Mark17 5 720 Oct-29-2023, 12:40 PM
Last Post: Mark17
  How to do 100 runs simulation based on the current codes? dududada 6 999 Sep-03-2023, 01:43 PM
Last Post: deanhystad
  How to programmatically stop a program in Jupyter Notebook? Mark17 11 37,254 Feb-12-2023, 01:41 PM
Last Post: jp21in
Thumbs Up Python 3 Jupyter notebook ternary plot data nicholas 0 955 Jan-21-2023, 05:01 PM
Last Post: nicholas
  Graphs from Jupyter notebook to word Scott 0 892 Nov-28-2022, 06:16 AM
Last Post: Scott
  Another program runs bho68 7 1,207 Nov-08-2022, 08:16 PM
Last Post: bho68
  Opening an empty Jupyter notebook in VSCODE Krischu 3 1,860 Mar-09-2022, 01:57 PM
Last Post: Larz60+
  Help Python vs Jupyter futureofAI 2 1,588 Oct-17-2021, 09:45 AM
Last Post: futureofAI
  How to do line continuation in Jupyter Notebook? Mark17 4 5,522 Sep-22-2021, 04:22 PM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020