How does `split()` work?

is other language also got similar this method?

It’s probably safe to say that many languages have such a mechanism (split/join relationship) and it makes sense that they would be string methods, regardless the language.

All languages must work with data, both structured and unstructured (primitive?). It follows that char data streams will be given similar treatment in any regard and appropriate methods for manipulating them will be built in to the language.

fullName = ["Mary", "Elizabeth", "Walker", "Mary-Beth"]


console.log(fullName.slice(0, 3))
// <- ["Mary", "Elizabeth", "Walker"]
console.log(fullName.slice(0,3).join(' '))
// <- "Mary Elizabeth Walker"
// <- ["Mary-Beth"]
// <- "Mary-Beth"
console.log(fullName.slice(-2).join(', '))
// <- "Walker, Mary-Beth"
1 Like

Thanks for your example code there. Looks similar with different language style. Just my side questions here. If in future I’m able to master python language, is it possible to master language java or others? or just better focus on python language since the java almost have same functions work? ,Im curious actually. Thanks @mtf a lots of thing I’m learn from you.

1 Like

Once we can master one language, others are not as difficult to learn owing that there is a lot of overlap in concepts and methodology. Every language has its particular strength, so there is some fitting of language to scenario depending upon optimization and scalability needed. As a learner it might be better to keep focus on the one language, Python in this case, rather than spreading one’s self too thin. The door is open after that point. Your goals will factor in to what you go ahead and learn next.

1 Like

I tried without using any built in string methods. If I understand correctly, this will have a time complexity of O(n) and space of O(1) since my variable will be considered a constant.
I am new to the Big O notation so trying to use it as often as possible.

But if I use split and len(split_list) -1, then will my space complexity change ?

I like the split method approach since its very concise. Can you help with the approach I need to know while practicing and for interviews etc ? (should I use both for each problem ?)

My code:
def count_char_x(word, x):
count = 0
index = 0

while (index + len(x)) <= len(word):
		if x == word[index:(index + len(x))]:
 			 count += 1
		index += 1
return count