-5

Now I am taking IBM Data Science Professional certificate' course. And, I am using Jupyter Notebook on 'IBM Watson Studio'. My question is this.

when I want to receive the keyboard input on Jupyter notebook, There is a problem like this.

enter image description here

I can't write any input to list 'a'. I want to put some string to 'a' like a=['h','e','l','l','o']. But, I can't write any input to list 'a'. So, list 'a' remains empty. How can I solve this problem?

Epsi95
  • 8,832
  • 1
  • 16
  • 34
  • 1
    it should not be empty, if you provide `['h','e','l','l','o']` also, list will not do what you are intending to get. The output datatype of `input()` is `str`. `list("abc")` is `['a', 'b', 'c']`. I think you want `ast.literal_eval` – Epsi95 Apr 18 '22 at 03:01
  • just to clarify, do you want to pass a list as an input to the input function? because if so you can achieve a similar result by formatting the input string and then using a list comprehension or for loop to populate the desired list. – Kaleba KB Keitshokile Apr 18 '22 at 03:41

1 Answers1

1

This should work fine, but you may have re-defined input somewhere in your code, or your notebook is bugged. Try the following:

x = input("Enter text: ")
a = list(x)
Freddy Mcloughlan
  • 4,129
  • 1
  • 13
  • 29