Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#Python, (削除) 119 (削除ここまで)(削除) 115 (削除ここまで) 91

Python, (削除) 119 (削除ここまで)(削除) 115 (削除ここまで) 91

lambda a,b:[a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a))if a[m:m+n]not in b][0]

Test cases:

| Input 1 | Input 2 | Output |
|----------+-------------+---------------|
| 'abcd' | 'abc' | 'd' |
| 'abcd' | 'dabc' | 'cd' |
| 'abcd' | 'dcbabbccd' | 'abc' |
| 'abcdf' | 'abcdebcdf' | 'abcdf' |
| 'abc' | 'abc' | (IndexError) |

Working on making it shorter, but this is my brain instinct. Not really much of a golfer yet.

Thanks to @user81655 and @NonlinearFruit for the extra bytes.

Edit:

Dang. Tried this code:

def z(a,b):
 for s in [a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a)-n+1)]:
 if s not in b:return s
 return''

Thought it was a few bytes shorter. Turns out it was 1 byte longer than what I had before the edit.

#Python, (削除) 119 (削除ここまで)(削除) 115 (削除ここまで) 91

lambda a,b:[a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a))if a[m:m+n]not in b][0]

Test cases:

| Input 1 | Input 2 | Output |
|----------+-------------+---------------|
| 'abcd' | 'abc' | 'd' |
| 'abcd' | 'dabc' | 'cd' |
| 'abcd' | 'dcbabbccd' | 'abc' |
| 'abcdf' | 'abcdebcdf' | 'abcdf' |
| 'abc' | 'abc' | (IndexError) |

Working on making it shorter, but this is my brain instinct. Not really much of a golfer yet.

Thanks to @user81655 and @NonlinearFruit for the extra bytes.

Edit:

Dang. Tried this code:

def z(a,b):
 for s in [a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a)-n+1)]:
 if s not in b:return s
 return''

Thought it was a few bytes shorter. Turns out it was 1 byte longer than what I had before the edit.

Python, (削除) 119 (削除ここまで)(削除) 115 (削除ここまで) 91

lambda a,b:[a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a))if a[m:m+n]not in b][0]

Test cases:

| Input 1 | Input 2 | Output |
|----------+-------------+---------------|
| 'abcd' | 'abc' | 'd' |
| 'abcd' | 'dabc' | 'cd' |
| 'abcd' | 'dcbabbccd' | 'abc' |
| 'abcdf' | 'abcdebcdf' | 'abcdf' |
| 'abc' | 'abc' | (IndexError) |

Working on making it shorter, but this is my brain instinct. Not really much of a golfer yet.

Thanks to @user81655 and @NonlinearFruit for the extra bytes.

Edit:

Dang. Tried this code:

def z(a,b):
 for s in [a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a)-n+1)]:
 if s not in b:return s
 return''

Thought it was a few bytes shorter. Turns out it was 1 byte longer than what I had before the edit.

Use better table and syntax highlighting
Source Link
mbomb007
  • 23.6k
  • 7
  • 66
  • 143

#Python, (削除) 119 (削除ここまで) (削除) 115 (削除ここまで) 91

lambda a,b:[a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a))if a[m:m+n]not in b][0]
lambda a,b:[a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a))if a[m:m+n]not in b][0]

Test cases:

| Input 1 | Input 2 | Output |
|----------+-------------+---------------|
| 'abcd' | 'abc' | 'd' |
| 'abcd' | 'dabc' | 'cd' |
| 'abcd' | 'dcbabbccd' | 'abc' |
| 'abcdf' | 'abcdebcdf' | 'abcdf' |
| 'abc' | 'abc' | (IndexError) |
| Input 1 | Input 2 | Output |
|----------+-------------+---------------|
| 'abcd' | 'abc' | 'd' |
| 'abcd' | 'dabc' | 'cd' |
| 'abcd' | 'dcbabbccd' | 'abc' |
| 'abcdf' | 'abcdebcdf' | 'abcdf' |
| 'abc' | 'abc' | (IndexError) |

Working on making it shorter, but this is my brain instinct. Not really much of a golfer yet.

Thanks to @user81655 and @NonlinearFruit for the extra bytes.

Edit:

Dang. Tried this code:

def z(a,b):
 for s in [a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a)-n+1)]:
 if s not in b:return s
 return''
def z(a,b):
 for s in [a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a)-n+1)]:
 if s not in b:return s
 return''

Thought it was a few bytes shorter. Turns out it was 1 byte longer than what I had before the edit.

#Python, (削除) 119 (削除ここまで) (削除) 115 (削除ここまで) 91

lambda a,b:[a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a))if a[m:m+n]not in b][0]

Test cases:

| Input 1 | Input 2 | Output |
|----------+-------------+---------------|
| 'abcd' | 'abc' | 'd' |
| 'abcd' | 'dabc' | 'cd' |
| 'abcd' | 'dcbabbccd' | 'abc' |
| 'abcdf' | 'abcdebcdf' | 'abcdf' |
| 'abc' | 'abc' | (IndexError) |

Working on making it shorter, but this is my brain instinct. Not really much of a golfer yet.

Thanks to @user81655 and @NonlinearFruit for the extra bytes.

Edit:

Dang. Tried this code:

def z(a,b):
 for s in [a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a)-n+1)]:
 if s not in b:return s
 return''

Thought it was a few bytes shorter. Turns out it was 1 byte longer than what I had before the edit.

#Python, (削除) 119 (削除ここまで) (削除) 115 (削除ここまで) 91

lambda a,b:[a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a))if a[m:m+n]not in b][0]

Test cases:

| Input 1 | Input 2 | Output |
|----------+-------------+---------------|
| 'abcd' | 'abc' | 'd' |
| 'abcd' | 'dabc' | 'cd' |
| 'abcd' | 'dcbabbccd' | 'abc' |
| 'abcdf' | 'abcdebcdf' | 'abcdf' |
| 'abc' | 'abc' | (IndexError) |

Working on making it shorter, but this is my brain instinct. Not really much of a golfer yet.

Thanks to @user81655 and @NonlinearFruit for the extra bytes.

Edit:

Dang. Tried this code:

def z(a,b):
 for s in [a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a)-n+1)]:
 if s not in b:return s
 return''

Thought it was a few bytes shorter. Turns out it was 1 byte longer than what I had before the edit.

#Python, (削除) 119 (削除ここまで) (削除) 115 (削除ここまで) 91

lambda a,b:[a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a))if a[m:m+n]not in b][0]

Test cases:

| Input 1 | Input 2 | Output Output|
|----------+-------------+---------------|
| 'abcd', 'abc' | 'abc' #| 'd' |
| 'abcd', 'dabc' | 'dabc' #| 'cd' |
| 'abcd', 'dcbabbccd' | 'dcbabbccd' #| 'abc' |
| 'abcdf', 'abcdebcdf' | #'abcdebcdf' |  'abcdf' |
| 'abc', 'abc' | 'abc' # |  (IndexError) |

Working on making it shorter, but this is my brain instinct. Not really much of a golfer yet.

Thanks to @user81655 and @NonlinearFruit for the extra bytes.

Edit:

Dang. Tried this code:

def z(a,b):
 for s in [a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a)-n+1)]:
 if s not in b:return s
 return''
def z(a,b):
 for s in [a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a)-n+1)]:
 if s not in b:return s
 return''

Thought it was a few bytes shorter. Turns out it was 1 byte longer than what I had before the edit.

#Python, (削除) 119 (削除ここまで) (削除) 115 (削除ここまで) 91

lambda a,b:[a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a))if a[m:m+n]not in b][0]

Test cases:

 Input Output
--------------------------------
'abcd', 'abc' # 'd'
'abcd', 'dabc' # 'cd'
'abcd', 'dcbabbccd' # 'abc'
'abcdf', 'abcdebcdf' # 'abcdf'
'abc', 'abc' # (IndexError)

Working on making it shorter, but this is my brain instinct. Not really much of a golfer yet.

Thanks to @user81655 and @NonlinearFruit for the extra bytes.

Edit:

Dang. Tried this code:

def z(a,b):
 for s in [a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a)-n+1)]:
 if s not in b:return s
 return''

Thought it was a few bytes shorter. Turns out it was 1 byte longer than what I had before the edit.

#Python, (削除) 119 (削除ここまで) (削除) 115 (削除ここまで) 91

lambda a,b:[a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a))if a[m:m+n]not in b][0]

Test cases:

| Input 1 | Input 2 | Output |
|----------+-------------+---------------|
| 'abcd' | 'abc' | 'd' |
| 'abcd' | 'dabc' | 'cd' |
| 'abcd'  | 'dcbabbccd' | 'abc' |
| 'abcdf' | 'abcdebcdf' |  'abcdf' |
| 'abc' | 'abc' |  (IndexError) |

Working on making it shorter, but this is my brain instinct. Not really much of a golfer yet.

Thanks to @user81655 and @NonlinearFruit for the extra bytes.

Edit:

Dang. Tried this code:

def z(a,b):
 for s in [a[m:m+n]for n in range(1,len(a)+1)for m in range(len(a)-n+1)]:
 if s not in b:return s
 return''

Thought it was a few bytes shorter. Turns out it was 1 byte longer than what I had before the edit.

added language type meta tag
Source Link
Loading
shorter
Source Link
Loading
saved 4 bytes
Source Link
Loading
correction to count. reinstated older, shorter code.
Source Link
Loading
used list comprehension instead
Source Link
Loading
Added test cases
Source Link
Loading
Source Link
Loading

AltStyle によって変換されたページ (->オリジナル) /