#Tisbury Treasure Hunt : Clean up

23 messages · Page 1 of 1 (latest)

zealous lynx
#

Hello everyone, I am new here. I am trying to solve the Tisbury Treasure Hunt task 5. It is asking to return a docstring and I am not getting at that.
Here, clean_up take tuple of tuples as parameter and output is needed in docstring. Please help me!
This is the code:

def clean_up(combined_record_group):
    report = []
    for records in combined_record_group:
        record = list(records)
        del record[1]
        report.append(record)
    return """ """.join(str(report))

Its showing the error shown below:

AssertionError: 
"[ [ ' S c r i m s h a w e d   W h a l e  [1794 chars] ] ]" != "('Scrimshawed Whale Tooth', 'Deserted Doc[875 chars]')\n"
Diff is 2753 characters long. Set self.maxDiff to None to see it.
marble fiber
#

It asks for a string, not a docstring 🙂

#

""" """ is the same exact thing as " " and ' '. They are all a single space, quoted differently.

#

" ".join(str(report)) is (1) converting report to a single str then (2) calling " ".join() on that str. join() iterates over whatever you pass it. Since you pass it a str, it iterates over the str, giving individual characters, then joins each char with a space.

#

You should read the hint on this exercise!

zealous lynx
#

@marble fiber Thank you for your explanation. I will focus on the hint of this exercise.

marble fiber
#

Note this is a tuple exercise, not a list exercise.

zealous lynx
#

Okay I will remove the list but it asks to drop the coordinate element in a tuple but how can I do that in tuple.

#

@marble fiber sorry I accidentally clicked on the call button.

marble fiber
#

Tuples can't be modified. They are immutable. But you can create new ones!

zealous lynx
#

Thank you for your support.

marble fiber
zealous lynx
#

Not yet but I will surely do it this time.

marble fiber
#

Keep us posted!

zealous lynx
#

i tried to remove list but could not do it and also getting an assertion error

    result = []
    for records in combined_record_group:
        report = []
        for index, record in enumerate(records):
            if index == 1:
                continue 
            report.append(record)
        result.append(tuple(report))
    output = str(result)
    return output.strip('[]')

output:

AssertionError: "('Sc[56 chars]lue'), ('Brass Spyglass', 'Abandoned Lighthous[808 chars]ow')" != "('Sc[56 chars]lue')\n('Brass Spyglass', 'Abandoned Lighthous[810 chars]')\n"
Diff is 3586 characters long. Set self.maxDiff to None to see it.

what should I do

marble fiber
#

The error is simply telling you that your function is returning the wrong thing.

#

If you look closely you might notice the expected output is supposed to have a newline between records, which your results do not have.

#

report is also still a list, not a tuple.

zealous lynx
#

but if it tuple then it become a whole single tuple using Concatenation and not tuples in tuple

marble fiber
#

Huh?

#

Eventually it all just becomes a string

zealous lynx
#

in this i changed it to tuple

  result = ()
    for records in combined_record_group:
        report = []
        for index, record in enumerate(records):
            if index == 1:
                continue 
            report.append(record)
        result += tuple(report)
    print(result)

and it gives output this here it is single tuple.

('Scrimshawed Whale Tooth', 'Deserted Docks', ('2', 'A'), 'Blue', 'Brass Spyglass', 'Abandoned Lighthouse', ('4', 'B'), 'Blue', 'Robot Parrot', 'Seaside Cottages', ('1', 'C'), 'Blue', 'Glass Starfish', 'Tangled Seaweed 

but the correct output is like this in which we can see tuples in a tuple.

"""('Scrimshawed Whale Tooth', 'Deserted Docks', ('2', 'A'), 'Blue')\n\
('Brass Spyglass', 'Abandoned Lighthouse', ('4', 'B'), 'Blue')\n\
('Robot Parrot', 'Seaside Cottages', ('1', 'C'), 'Blue')\n\
('Glass Starfish', 'Tangled Seaweed Patch', ('6', 'D'), 'Orange')\n\
zealous lynx
#

@marble fiber Thank you for your help i solved it this time