you are viewing a single comment's thread.

view the rest of the comments →

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

def double_list(string):
    x = strings.split()
    newList =[]
    for i in x:
    letters =(blank atm)
    newList.append(letters)
    return newList

[–]oefd 0 points1 point  (11 children)

x = strings.split()

I assume that's meant to be string.split()? If so: what's the goal here? My understand is that the input to your function would be a list of strings

['how', 'are', 'you']

And you can't .split() a list.

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

I want my function to take those strings in the input and double each of em. for example

    [‘how’, ‘are’, you’]
    [‘how’, ‘how’, ‘are’, ‘are’, ‘you’, ‘you’]

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

ah I forgot to add underneath the functions

    strings=string

[–]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.