0

I'm doing a project where I need to insert coordinates in the console to return a place in a grid. My grid is 10*10 and has numbers in the rows and Letters in the columns. I want to be able to input something like A1 and for it to be interpreted as "column1, row1"

So far I have got:

def get_coor():
    user_input = input("Please enter coordinates (row,col) ? ")
    coor = user_input.split(" ")
    return coor

But I'm only able to split if I have a space. Is there any other function to help me in this situation?

  • Possible duplicate of [Split Strings with Multiple Delimiters?](https://stackoverflow.com/questions/1059559/split-strings-with-multiple-delimiters) or [Python: Split string with multiple delimiters](https://stackoverflow.com/questions/4998629/python-split-string-with-multiple-delimiters) – Draken Dec 17 '18 at 17:08

1 Answers1

1

Strings are iterable in Python.

If you write:

user_input = input("Please enter coordinates (row,col)?")
<input A1>

Then user_input[0] will be A and user_input[1] will be 1.

Therefore, no need for the split :) Split is used precisely for the use case when there is a space: it returns a list of all the strings between the occurrences of the character given as an argument (in your case a space).

FranciscoRZ
  • 72
  • 1
  • 11