0

join tupe and list logic

I am working out the logic of a join for list and tuples however i am not seeing the logic flow what i am looking for is in the comments of the code https://code.sololearn.com/cH3WXG8bWAIr

12th Mar 2019, 6:05 PM
Michael Harrall
Michael Harrall - avatar
8 Réponses
+ 3
The format is directly connected to the method. Append adds the whole object to the list, so if you add a list, you will have a list in a list: [1, 2, [3, 4]] Extend on the other hand 'unpacks' the list and every element will be added separately, so the brackets disappear: [1, 2, 3, 4]
12th Mar 2019, 7:12 PM
HonFu
HonFu - avatar
+ 2
The method extend fills up your list with the elements of another list. The method append inserts the whole object at the end of your list. So depending on the type of your second argument you'd use the one or the other.
12th Mar 2019, 6:19 PM
HonFu
HonFu - avatar
+ 2
Yep, you got it. Congrats! :)
13th Mar 2019, 12:00 AM
HonFu
HonFu - avatar
+ 1
The main problem is starting the lines with ans =.... extend and append are in-place methods, meaning they change the list itself and return nothing. Now if you write ans = ans.extend, your ans is directly overwritten by this 'nothing': None. Just write ans.extend(whatever) and you're a big step closer.
12th Mar 2019, 11:45 PM
HonFu
HonFu - avatar
0
HonFu I will look at extend the problem I have with append is the format does not come out correct
12th Mar 2019, 6:49 PM
Michael Harrall
Michael Harrall - avatar
0
well extend gives me one portion of the solution but not the whol and now my logic is not working i do not understand why it is failing
12th Mar 2019, 11:39 PM
Michael Harrall
Michael Harrall - avatar
0
Honfu thanks for that what i am fighting right now that makes no sense is File "..\Playground\", line 14 else type(to_add) is list: ^ SyntaxError: invalid syntax
12th Mar 2019, 11:47 PM
Michael Harrall
Michael Harrall - avatar
0
I think i have it would you mind looking at it @HonFu
12th Mar 2019, 11:52 PM
Michael Harrall
Michael Harrall - avatar