0

I'm taking a Udemy course on Python (my first language) and the environment of choice is Jupyter. When I try to write that code in Sublime, I can't get the same output (there are no errors). Udemy code

def splicer(mystring):
    if len(mystring)%2 == 0:
        return "Even"
    else:
        return "Odd"

names = ["Andy", "Eve", "Sally"]
list(map(splicer,names))
thumbtackthief
  • 6,093
  • 10
  • 41
  • 87
B9M8
  • 47
  • 5

2 Answers2

3

You need to print the result!

print(list(map(splicer,names)))

In Jupyter, it automatically prints the representation of a statement, where as when you're writing applications, you need to print if you want the result to be shown on the screen.

Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100
1

jupyter acts as a python interpreter, so if you enter an object it automatically prints the result underneath. Sublime is a text editor, so it is only executing the code you are giving it. It is running list(map(splicer,names)) but it is not displaying the object because you are not telling it to.

So the interpreter (jupyter) is executing your python code in real time and interpreting (printing to screen). The text editor is only executing your python code. Therefore, you need to add a print statement to your object to have the editor print the object to screen:

print(list(map(splicer,names)))
d_kennetz
  • 5,219
  • 5
  • 21
  • 44