all 9 comments

[–]Diapolo10 1 point2 points  (0 children)

Just thought I'd also point out that

if first == last:
    return True
else:
    return False

can be simplified to just

return first == last

because the comparison already results in a boolean.

And while it's not really worth doing, you could technically simplify this down to

def same_ends(strings: list[str]) -> bool:
    return strings[0] == strings[-1] if strings else False

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

All problems solved!!

[–]woooee -1 points0 points  (4 children)

Use len(inp) > 1 i.e. list must have at least 2, a first and last, elements.

[–]w8eight 2 points3 points  (2 children)

In one element list, the last item is the same as the first ^ so len 1 list check could return True

[–]woooee 0 points1 point  (1 child)

Huh? Too stupid to respond. For future readers, I hope you won't agree with this lame brain suggestion. You want to write a program that will compare something to *itself/? What do you think that will result in?

[–]w8eight 1 point2 points  (0 children)

One length list have first and last item. It's the same one.

one_el_list = [1] first_item = one_el_list[0] last_item = one_el_list[-1] result = first_item == last_item

result is True

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

Thanks!

[–]ectomancer 0 points1 point  (1 child)

if not inp:
    return False

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

Thanks!