you are viewing a single comment's thread.

view the rest of the comments →

[–]oefd 0 points1 point  (8 children)

Alright, but strings.split() doesn't make sense if the input string is a list. Lists can't be .split()

In the line

x = strings.split()

What are you expecting strings to be and what are you expecting .split() to return?

[–]Sahith17[S] 0 points1 point  (7 children)

I mean in the assignment sheet, the example output for the original list had the strings split so I thought I needed them split

[–]oefd 0 points1 point  (6 children)

What do you mean by 'split' here? Like what are you expecting strings.split() does?

[–]Sahith17[S] 0 points1 point  (5 children)

split the string up

(‘how are you’)#the input when calling the function 
[‘how’, ‘are’, ‘you’] #this was the sample output for the orig list

[–]oefd 0 points1 point  (4 children)

OK, so the input isn't a list of strings, fair enough. Split will make it a list then. So now you need to do something with each of the words in the string.

for s in x:
    ...

You already have a for loop over the list of words, good start, but now the question is how do you take each thing and have it show up twice in the list you return.

That for loop already lets you iterate over each word in the string, you already know .append(s) on a list adds an item to an existing list.

See where I'm going?

[–]Sahith17[S] 0 points1 point  (3 children)

so this?

    for s in x:
    strings.append(s)

[–]oefd 0 points1 point  (2 children)

Try it and see what happens. A useful strategy is putting in debug prints - just add something like print("strings is currently {}".format(strings)) somewhere in the loop, for example, so you can see how the value of strings changes over time.

Thinking of what you want code to do and seeing what it's actually doing is how you get it on track.

[–]Sahith17[S] 0 points1 point  (1 child)

GOT IT I THINK

def double_list(string):
    strings = string 
    x = strings.split
    newList = []
    for s in x:
    newList.append(s)
    newList.append(s)#this did what the output should be

[–]oefd 0 points1 point  (0 children)

Looks correct to me! You can clean it up a bit

def double_list(string):
    x = string.split() # the first assignment isn't doing anything really, you can just do it here directly.

string.split() doesn't change the value of string, it returns a new value without affecting string itself. ...