2 Replies - 2200 Views - Last Post: 30 December 2012 - 09:45 AM

#1 andrewsw   User is online

  • never lube your breaks
  • member icon

Reputation: 6795
  • View blog
  • Posts: 28,082
  • Joined: 12-December 12

endswith alternative

Posted 17 December 2012 - 03:30 PM

Description: The function will return true/false if the first argument ends with the second. Python already has endswith() but it thought this was interesting anyway.
def end_other(x, y):
    return (x[::-1][0:len(y)]).lower() == (y[::-1]).lower()

Is This A Good Question/Topic? 0
  • +

Replies To: endswith alternative

#2 Simown   User is offline

  • Blue Sprat
  • member icon

Reputation: 322
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: endswith alternative

Posted 30 December 2012 - 09:41 AM

It's not precisely an "endswith" alternative, the signature for endswith lets you specify a position where to search for in the string (start and/or end), also you can provide a tuple of suffixes which the string could end with.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is online

  • never lube your breaks
  • member icon

Reputation: 6795
  • View blog
  • Posts: 28,082
  • Joined: 12-December 12

Re: endswith alternative

Posted 30 December 2012 - 09:45 AM

I am not seriously suggesting this as an alternative to endswith; it is just, I thought!, an interesting piece of Python code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1