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
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]
+ 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.
+ 2
Yep, you got it. Congrats! :)
+ 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.
0
HonFu I will look at extend the problem I have with append is the format does not come out correct
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
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
0
I think i have it would you mind looking at it @HonFu