I wrote the following code to substitute for .join()
from os.path import join
path_segment_1 = "/Home/User"
path_segment_2 = "Codecademy/videos"
path_segment_3 = "cat_videos/surprised_cat.mp4"
# join all three of the paths here!
#print(join(path_segment_1, path_segment_2, path_segment_3))
def myjoin(*args,joined_string=None):
if joined_string is None:
joined_string = []
print(args[0])
for arg in args:
joined_string += arg
print(joined_string)
print("\n")
return joined_string
myjoin(path_segment_1, path_segment_2, path_segment_3)
And my output looks like this:
/Home/User
[β/β, βHβ, βoβ, βmβ, βeβ, β/β, βUβ, βsβ, βeβ, βrβ]
[β/β, βHβ, βoβ, βmβ, βeβ, β/β, βUβ, βsβ, βeβ, βrβ, βCβ, βoβ, βdβ, βeβ, βcβ, βaβ, βdβ, βeβ, βmβ, βyβ, β/β, βvβ, βiβ, βdβ, βeβ, βoβ, βsβ]
[β/β, βHβ, βoβ, βmβ, βeβ, β/β, βUβ, βsβ, βeβ, βrβ, βCβ, βoβ, βdβ, βeβ, βcβ, βaβ, βdβ, βeβ, βmβ, βyβ, β/β, βvβ, βiβ, βdβ, βeβ, βoβ, βsβ, βcβ, βaβ, βtβ, ββ, βvβ, βiβ, βdβ, βeβ, βoβ, βsβ, β/β, βsβ, βuβ, βrβ, βpβ, βrβ, βiβ, βsβ, βeβ, βdβ, 'β, βcβ, βaβ, βtβ, β.β, βmβ, βpβ, β4β]
Can someone please explain me why when I print args[0] before the iteration I get β/Home/Userβ as a whole but when I print it again in the for loop the whole string is exploded into characters?
Below is the actual solution. I do not understand the necessity to assign joined_string = args[0] for the iteration to work.
def myjoin(*args):
joined_string = args[0]
for arg in args[1:]:
joined_string += '/' + arg
return joined_string
Any help is appreciated, Thanks!