prompt large_stringlengths 72 9.34k | completion large_stringlengths 0 7.61k |
|---|---|
<|file_name|>ssf_reader.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python -*- coding:utf-8 -*-
__Author__ = "Riyaz Ahmad Bhat"
__Email__ = "riyaz.ah.bhat@gmail.com"
import re
from collections import namedtuple
from sanity_checker import SanityChecker
class DefaultList(list):
"""Equivalent of Default dictionari... | attributes['lemma_'],attributes['cat_'],attributes['gen_'],attributes['num_'],\
attributes['per_'],attributes['case_'],attributes['vib_'],attributes['tam_'] = \
self.morphFeatures (value) |
<|file_name|>ssf_reader.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python -*- coding:utf-8 -*-
__Author__ = "Riyaz Ahmad Bhat"
__Email__ = "riyaz.ah.bhat@gmail.com"
import re
from collections import namedtuple
from sanity_checker import SanityChecker
class DefaultList(list):
"""Equivalent of Default dictionari... | assert len(value.split(":")) == 2 # no need to process trash! FIXME
attributes['drel_'], attributes['parent_'] = re.sub("'|\"",'',value).split(":")
assert attributes['drel_'] and attributes['parent_'] != "" # no need to process trash! FIXME |
<|file_name|>ssf_reader.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python -*- coding:utf-8 -*-
__Author__ = "Riyaz Ahmad Bhat"
__Email__ = "riyaz.ah.bhat@gmail.com"
import re
from collections import namedtuple
from sanity_checker import SanityChecker
class DefaultList(list):
"""Equivalent of Default dictionari... | variable = str(key) + "_"
if variable == "name_": attributes['chunkId_'] = re.sub("'|\"",'',value)
attributes[variable] = re.sub("'|\"",'',value) |
<|file_name|>ssf_reader.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python -*- coding:utf-8 -*-
__Author__ = "Riyaz Ahmad Bhat"
__Email__ = "riyaz.ah.bhat@gmail.com"
import re
from collections import namedtuple
from sanity_checker import SanityChecker
class DefaultList(list):
"""Equivalent of Default dictionari... | attributes['chunkId_'] = re.sub("'|\"",'',value) |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | suite.addTest(unittest.makeSuite(GeneratorEventTest)) |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | def setUp(self):
self.observers_called = 0
self.event = Event()
def probe(self):
self.observers_called += 1
def test_can_notify_all_observers(self):
self.event.post_observers.append(self.probe)
self.event.pre_observers.append(self.probe)
ass... |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | self.observers_called = 0
self.event = Event() |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | self.observers_called += 1 |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | self.event.post_observers.append(self.probe)
self.event.pre_observers.append(self.probe)
assert_equals(0, self.observers_called)
self.event()
assert_equals(2, self.observers_called) |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | def test_returns_first_non_null_result(self):
event = FetchFirstResultEvent([])
event.post_observers.append(lambda: None)
event.post_observers.append(lambda: 1)
event.post_observers.append(lambda: 2)
assert_equals(1, event())
def test_passes_all_event_parame... |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | event = FetchFirstResultEvent([])
event.post_observers.append(lambda: None)
event.post_observers.append(lambda: 1)
event.post_observers.append(lambda: 2)
assert_equals(1, event()) |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | event = FetchFirstResultEvent([])
event.post_observers.append(lambda foo, bar=None: foo)
event.post_observers.append(lambda foo, bar=None: bar or foo)
assert_equals(4, event(4))
assert_equals(6, event(None, bar=6)) |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | def test_can_unroll_lists(self):
event = GeneratorEvent([])
event.post_observers.append(lambda: [1, 2, 3])
event.post_observers.append(lambda: ('a', 'b'))
assert_equals([1, 2, 3, 'a', 'b'], list(event()))
def test_can_return_non_iterable_items(self):
event =... |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | event = GeneratorEvent([])
event.post_observers.append(lambda: [1, 2, 3])
event.post_observers.append(lambda: ('a', 'b'))
assert_equals([1, 2, 3, 'a', 'b'], list(event())) |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | event = GeneratorEvent([])
event.post_observers.append(lambda: [1, ])
event.post_observers.append(lambda: None)
event.post_observers.append(lambda: 5)
event.post_observers.append(lambda: 'some value')
assert_equals([1, None, 5, 'some value'], list(event())) |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(EventTest))
suite.addTest(unittest.makeSuite(FetchFirstResultEventTest))
suite.addTest(unittest.makeSuite(GeneratorEventTest))
return suite |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | unittest.main(defaultTest='suite') |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | setUp |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | probe |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | test_can_notify_all_observers |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | test_returns_first_non_null_result |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | test_passes_all_event_parameters_to_observers |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | test_can_unroll_lists |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | test_can_return_non_iterable_items |
<|file_name|>events_test.py<|end_file_name|><|fim▁begin|># This file is a part of MediaDrop (http://www.mediadrop.net),
# Copyright 2009-2014 MediaDrop contributors
# For the exact contribution history, see the git revision log.
# The source code contained in this file is licensed under the GPLv3 or
# (at your option) ... | suite |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | @property
def nonoauth_params(self):
|
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
<|fim_middle|>
<|fim▁end|> | """The OAuth version of the WebOb Request.
Provides an easier way to obtain OAuth request parameters
(e.g. oauth_token) from the WSGI environment."""
def _checks_positive_for_oauth(self, params_var):
"""Simple check for the presence of OAuth parameters."""
checks = [ p.find('oauth... |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | """Simple check for the presence of OAuth parameters."""
checks = [ p.find('oauth_') >= 0 for p in params_var ]
return True in checks |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | extracted = {}
# Check for OAuth in the Header
if 'authorization' in self.headers:
auth_header = self.headers['authorization']
# Check that the authorization header is OAuth.
if auth_header[:6] == 'OAuth ':
auth_header = auth_header.lstri... |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | extracted = {}
if self._checks_positive_for_oauth(self.str_POST):
extracted = dict([ (k, v,) for k, v in self.str_POST.iteritems()
if (k.find('oauth_') >= 0) ])
return extracted |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | extracted = {}
if self._checks_positive_for_oauth(self.str_GET):
extracted = dict([ (k, v,) for k, v in self.str_GET.iteritems()
if (k.find('oauth_') >= 0) ])
return extracted |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | params = WebObRequest.params.fget(self)
return NestedMultiDict(params, self.str_oauth_header) |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | """Simple way to get the OAuth parameters without sifting through
the entire stack of parameters.
We check the header first, because it is low hanging fruit.
However, it would be more efficient to check for the POSTed
parameters, because the specification defines the POST met... |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | """Simple way to get the non-OAuth parameters from the request."""
oauth_param_keys = self.oauth_params.keys()
return dict([(k, v) for k, v in self.params.iteritems() if k not in oauth_param_keys]) |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | auth_header = self.headers['authorization']
# Check that the authorization header is OAuth.
if auth_header[:6] == 'OAuth ':
auth_header = auth_header.lstrip('OAuth ')
try:
# Extract the parameters from the header.
... |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | auth_header = auth_header.lstrip('OAuth ')
try:
# Extract the parameters from the header.
extracted = oauth2.Request._split_header(auth_header)
except:
raise Error('Unable to parse OAuth parameters from '
... |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | extracted = dict([ (k, v,) for k, v in self.str_POST.iteritems()
if (k.find('oauth_') >= 0) ]) |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | extracted = dict([ (k, v,) for k, v in self.str_GET.iteritems()
if (k.find('oauth_') >= 0) ]) |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | _checks_positive_for_oauth |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | str_oauth_header |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | str_oauth_POST |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | str_oauth_GET |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | params |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | oauth_params |
<|file_name|>request.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
import oauth2 # XXX pumazi: factor this out
from webob.multidict import MultiDict, NestedMultiDict
from webob.request import Request as WebObRequest
__all__ = ['Request']
class Request(WebObRequest):
"""The OAuth version of the W... | nonoauth_params |
<|file_name|>16.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
from typing import List, Optional
"""
16. 3Sum Closest
https://leetcode.com/problems/3sum-closest/
"""
def bsearch(nums, left, right, res, i, j, target):
while left <= right:
middle = (left + right) // 2
candidate = nums[i] + num... |
class Solution:
def threeSumClosest(self, nums: List[int], target: int) -> Optional[int]:
res = None |
<|file_name|>16.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
from typing import List, Optional
"""
16. 3Sum Closest
https://leetcode.com/problems/3sum-closest/
"""
def bsearch(nums, left, right, res, i, j, target):
<|fim_middle|>
class Solution:
def threeSumClosest(self, nums: List[int], target: in... | while left <= right:
middle = (left + right) // 2
candidate = nums[i] + nums[j] + nums[middle]
if res is None or abs(candidate - target) < abs(res - target):
res = candidate
if candidate == target:
return res
elif candidate > target:
right ... |
<|file_name|>16.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
from typing import List, Optional
"""
16. 3Sum Closest
https://leetcode.com/problems/3sum-closest/
"""
def bsearch(nums, left, right, res, i, j, target):
while left <= right:
middle = (left + right) // 2
candidate = nums[i] + num... | def threeSumClosest(self, nums: List[int], target: int) -> Optional[int]:
res = None
nums = sorted(nums)
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
res = bsearch(nums, j + 1, len(nums) - 1, res, i, j, target)
return res |
<|file_name|>16.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
from typing import List, Optional
"""
16. 3Sum Closest
https://leetcode.com/problems/3sum-closest/
"""
def bsearch(nums, left, right, res, i, j, target):
while left <= right:
middle = (left + right) // 2
candidate = nums[i] + num... | res = None
nums = sorted(nums)
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
res = bsearch(nums, j + 1, len(nums) - 1, res, i, j, target)
return res |
<|file_name|>16.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
from typing import List, Optional
"""
16. 3Sum Closest
https://leetcode.com/problems/3sum-closest/
"""
def bsearch(nums, left, right, res, i, j, target):
while left <= right:
middle = (left + right) // 2
candidate = nums[i] + num... | sol = Solution()
print(sol.threeSumClosest([-111, -111, 3, 6, 7, 16, 17, 18, 19], 13))
return 0 |
<|file_name|>16.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
from typing import List, Optional
"""
16. 3Sum Closest
https://leetcode.com/problems/3sum-closest/
"""
def bsearch(nums, left, right, res, i, j, target):
while left <= right:
middle = (left + right) // 2
candidate = nums[i] + num... | res = candidate |
<|file_name|>16.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
from typing import List, Optional
"""
16. 3Sum Closest
https://leetcode.com/problems/3sum-closest/
"""
def bsearch(nums, left, right, res, i, j, target):
while left <= right:
middle = (left + right) // 2
candidate = nums[i] + num... | return res |
<|file_name|>16.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
from typing import List, Optional
"""
16. 3Sum Closest
https://leetcode.com/problems/3sum-closest/
"""
def bsearch(nums, left, right, res, i, j, target):
while left <= right:
middle = (left + right) // 2
candidate = nums[i] + num... | right = middle - 1 |
<|file_name|>16.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
from typing import List, Optional
"""
16. 3Sum Closest
https://leetcode.com/problems/3sum-closest/
"""
def bsearch(nums, left, right, res, i, j, target):
while left <= right:
middle = (left + right) // 2
candidate = nums[i] + num... | left = middle + 1 |
<|file_name|>16.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
from typing import List, Optional
"""
16. 3Sum Closest
https://leetcode.com/problems/3sum-closest/
"""
def bsearch(nums, left, right, res, i, j, target):
while left <= right:
middle = (left + right) // 2
candidate = nums[i] + num... | raise SystemExit(main()) |
<|file_name|>16.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
from typing import List, Optional
"""
16. 3Sum Closest
https://leetcode.com/problems/3sum-closest/
"""
def <|fim_middle|>(nums, left, right, res, i, j, target):
while left <= right:
middle = (left + right) // 2
candidate = nums[i... | bsearch |
<|file_name|>16.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
from typing import List, Optional
"""
16. 3Sum Closest
https://leetcode.com/problems/3sum-closest/
"""
def bsearch(nums, left, right, res, i, j, target):
while left <= right:
middle = (left + right) // 2
candidate = nums[i] + num... | threeSumClosest |
<|file_name|>16.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
from typing import List, Optional
"""
16. 3Sum Closest
https://leetcode.com/problems/3sum-closest/
"""
def bsearch(nums, left, right, res, i, j, target):
while left <= right:
middle = (left + right) // 2
candidate = nums[i] + num... | main |
<|file_name|>volread.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright (C) 2012, Almar Klein
#
# Visvis is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.
import visvis as vv
import numpy as np
import os
# Try importing imageio
imageio = None
... |
elif imageio is not None:
return imageio.volread(filename) |
<|file_name|>volread.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright (C) 2012, Almar Klein
#
# Visvis is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.
import visvis as vv
import numpy as np
import os
# Try importing imageio
imageio = None
... | """ volread(filename)
Read volume from a file. If filename is 'stent', read a dedicated
test dataset. For reading any other kind of volume, the imageio
package is required.
"""
if filename == 'stent':
# Get full filename
path = vv.misc.getResourceDir()
fil... |
<|file_name|>volread.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright (C) 2012, Almar Klein
#
# Visvis is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.
import visvis as vv
import numpy as np
import os
# Try importing imageio
imageio = None
... | path = vv.misc.getResourceDir()
filename2 = os.path.join(path, 'stent_vol.ssdf')
if os.path.isfile(filename2):
filename = filename2
else:
raise IOError("File '%s' does not exist." % filename)
# Load
s = vv.ssdf.load(filename)
return s.vol.a... |
<|file_name|>volread.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright (C) 2012, Almar Klein
#
# Visvis is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.
import visvis as vv
import numpy as np
import os
# Try importing imageio
imageio = None
... | filename = filename2 |
<|file_name|>volread.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright (C) 2012, Almar Klein
#
# Visvis is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.
import visvis as vv
import numpy as np
import os
# Try importing imageio
imageio = None
... | raise IOError("File '%s' does not exist." % filename) |
<|file_name|>volread.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright (C) 2012, Almar Klein
#
# Visvis is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.
import visvis as vv
import numpy as np
import os
# Try importing imageio
imageio = None
... | return imageio.volread(filename) |
<|file_name|>volread.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright (C) 2012, Almar Klein
#
# Visvis is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.
import visvis as vv
import numpy as np
import os
# Try importing imageio
imageio = None
... | raise RuntimeError("visvis.volread needs the imageio package to read arbitrary files.") |
<|file_name|>volread.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright (C) 2012, Almar Klein
#
# Visvis is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.
import visvis as vv
import numpy as np
import os
# Try importing imageio
imageio = None
... | vol = vv.volread('stent')
t = vv.volshow(vol)
t.renderStyle = 'mip' # maximum intensity projection (is the default) |
<|file_name|>volread.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright (C) 2012, Almar Klein
#
# Visvis is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.
import visvis as vv
import numpy as np
import os
# Try importing imageio
imageio = None
... | volread |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | data, choosers, spec, probabilities = request.param
return {
'data': data,
'choosers': choosers,
'spec': spec,
'probabilities': probabilities
} |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | filen = os.path.join(
os.path.dirname(__file__), 'data', test_data['choosers'])
return pd.read_csv(filen) |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | return test_data['spec'] |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | return eval_variables(spec.index, choosers) |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | utils = choosers_dm.dot(spec).astype('float')
return pd.DataFrame(
utils.as_matrix().reshape(test_data['probabilities'].shape),
columns=test_data['probabilities'].columns) |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | probs = mnl.utils_to_probs(utilities)
pdt.assert_frame_equal(probs, test_data['probabilities']) |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | with pytest.raises(RuntimeError):
mnl.utils_to_probs(
pd.DataFrame([[1, 2, np.inf, 3]])) |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | probs = pd.DataFrame(
[[1, 0, 0], [0, 1, 0]], columns=['a', 'b', 'c'], index=['x', 'y'])
choices = mnl.make_choices(probs)
pdt.assert_series_equal(
choices,
pd.Series([0, 1], index=['x', 'y'])) |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | probs = mnl.utils_to_probs(utilities)
choices = mnl.make_choices(probs)
pdt.assert_series_equal(
choices,
pd.Series([1, 2], index=[0, 1])) |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | return pd.DataFrame({
'attr': ['a', 'b', 'c', 'b']},
index=['w', 'x', 'y', 'z']) |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | return pd.DataFrame({
'prop': [10, 20, 30, 40]},
index=[1, 2, 3, 4]) |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | expected = pd.DataFrame({
'attr': ['a'] * 4 + ['b'] * 4 + ['c'] * 4 + ['b'] * 4,
'prop': [10, 20, 30, 40] * 4,
'chooser_idx': ['w'] * 4 + ['x'] * 4 + ['y'] * 4 + ['z'] * 4},
index=[1, 2, 3, 4] * 4)
interacted = mnl.interaction_dataset(
interaction_choosers, interaction_a... |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | expected = pd.DataFrame({
'attr': ['a'] * 2 + ['b'] * 2 + ['c'] * 2 + ['b'] * 2,
'prop': [30, 40, 10, 30, 40, 10, 20, 10],
'chooser_idx': ['w'] * 2 + ['x'] * 2 + ['y'] * 2 + ['z'] * 2},
index=[3, 4, 1, 3, 4, 1, 2, 1])
interacted = mnl.interaction_dataset(
interaction_cho... |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | test_data |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | choosers |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | spec |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | choosers_dm |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | utilities |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | test_utils_to_probs |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | test_utils_to_probs_raises |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | test_make_choices_only_one |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | test_make_choices_real_probs |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | interaction_choosers |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | interaction_alts |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | test_interaction_dataset_no_sample |
<|file_name|>test_mnl.py<|end_file_name|><|fim▁begin|># ActivitySim
# Copyright (C) 2014-2015 Synthicity, LLC
# See full license in LICENSE.txt.
import os.path
import numpy as np
import pandas as pd
import pandas.util.testing as pdt
import pytest
from ..activitysim import eval_variables
from .. import mnl
# this i... | test_interaction_dataset_sampled |
<|file_name|>test_secrecy.py<|end_file_name|><|fim▁begin|># Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# ... | # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, |
<|file_name|>test_secrecy.py<|end_file_name|><|fim▁begin|># Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# ... | t = String().secret().constrain(length_between(4,6))
with pytest.raises(ValidationFailed) as excinfo:
t.check("xxx")
message = str(excinfo)
assert "xxx" not in message |
<|file_name|>test_secrecy.py<|end_file_name|><|fim▁begin|># Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# ... | t = String().constrain(length_between(4,6)).secret()
with pytest.raises(ValidationFailed) as excinfo:
t.check("xxx")
message = str(excinfo)
assert "xxx" not in message |
<|file_name|>test_secrecy.py<|end_file_name|><|fim▁begin|># Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# ... | test_secrecy_declared_before |
<|file_name|>test_secrecy.py<|end_file_name|><|fim▁begin|># Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# ... | test_secrecy_declared_after |
<|file_name|>try_except_finally.py<|end_file_name|><|fim▁begin|>'''
c++ finally
'''
def myfunc():
b = False
try:
print('trying something that will fail...')
print('some call that fails at runtime')
f = open('/tmp/nosuchfile')
except:
print('got exception')
finally:
print('finally cleanup')
b = True
<|f... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.