In this article, we will discuss how to insert a space between the characters of all elements of a given array of string.
Suppose we have an array of string as follows: A = ["geeks", "for", "geeks"] then when we insert a space between the characters of all elements of the above array we get the following output. A = ["g e e k s", "f o r", "g e e k s"]
To do this we will use np.char.join(). This method basically returns a string in which the individual characters are joined by separator character that is specified in the method. Here the separator character used is space.
Syntax: np.char.join(sep, string)
sep: is any specified separator
string: is any specified string.
Printing the Original Array: ['geeks' 'for' 'geeks'] Printing the array after inserting spacebetween the elements ['g e e k s' 'f o r' 'g e e k s']
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.