Skip to main content
Code Review

Return to Question

Post Reopened by Ludisposed, Peilonrayz , Sᴀᴍ Onᴇᴌᴀ , 200_success, Billal BEGUERADJ
added 16 characters in body
Source Link
200_success
  • 145.6k
  • 22
  • 190
  • 479

My function needs two params(a,b) and if...break, which seems redundant. Can it be made prettier?

def slice_list(lst,num):
"""
Given a list or Numpy array,
get consecutive tuples based on specific window. 
"""
 rst = []
 for i,_ in enumerate(lst):
 a = i
 b = i + num
 if len(lst[a:b])<num:
 break
 rst.append(tuple(lst[a:b]))
 return rst

Example:

>>> lst = np.array([10, 11, 12, 13, 26, 28])
>>> slice_list(lst,4)
[(10, 11, 12, 13), (11, 12, 13, 26), (12, 13, 26, 28)]

My function needs two params(a,b) and if...break, which seems redundant. Can it be made prettier?

def slice_list(lst,num):
"""
Given a list or Numpy array,
get consecutive tuples based on specific window. 
"""
 rst = []
 for i,_ in enumerate(lst):
 a = i
 b = i + num
 if len(lst[a:b])<num:
 break
 rst.append(tuple(lst[a:b]))
 return rst

Example:

>>> lst = np.array([10, 11, 12, 13, 26, 28])
>>> slice_list(lst,4)
[(10, 11, 12, 13), (11, 12, 13, 26), (12, 13, 26, 28)]

My function needs two params(a,b) and if...break, which seems redundant. Can it be made prettier?

def slice_list(lst,num):
"""
Given a list or Numpy array,
get consecutive tuples based on specific window. 
"""
 rst = []
 for i,_ in enumerate(lst):
 a = i
 b = i + num
 if len(lst[a:b])<num:
 break
 rst.append(tuple(lst[a:b]))
 return rst

Example:

>>> lst = np.array([10, 11, 12, 13, 26, 28])
>>> slice_list(lst,4)
[(10, 11, 12, 13), (11, 12, 13, 26), (12, 13, 26, 28)]
fix indentation so code block won't be broken up
Source Link

My function needs two params(a,b) and if...break, which seems redundant. Can it be made prettier?

def slice_list(lst,num):
"""
Given a list or Numpy array,
get consecutive tuples based on specific window. 
"""
 rst = []
 for i,_ in enumerate(lst):
 a = i
 b = i + num
 if len(lst[a:b])<num:
 break
 rst.append(tuple(lst[a:b]))
 return rst

Given a list or Numpy array, get consecutive tuples based on specific window. """ rst = [] for i,_ in enumerate(lst): a = i b = i + num if len(lst[a:b])<num: break rst.append(tuple(lst[a:b])) return rst

Example:

>>> lst = np.array([10, 11, 12, 13, 26, 28])
>>> slice_list(lst,4)
[(10, 11, 12, 13), (11, 12, 13, 26), (12, 13, 26, 28)]

My function needs two params(a,b) and if...break, which seems redundant. Can it be made prettier?

def slice_list(lst,num):
"""

Given a list or Numpy array, get consecutive tuples based on specific window. """ rst = [] for i,_ in enumerate(lst): a = i b = i + num if len(lst[a:b])<num: break rst.append(tuple(lst[a:b])) return rst

Example:

>>> lst = np.array([10, 11, 12, 13, 26, 28])
>>> slice_list(lst,4)
[(10, 11, 12, 13), (11, 12, 13, 26), (12, 13, 26, 28)]

My function needs two params(a,b) and if...break, which seems redundant. Can it be made prettier?

def slice_list(lst,num):
"""
Given a list or Numpy array,
get consecutive tuples based on specific window. 
"""
 rst = []
 for i,_ in enumerate(lst):
 a = i
 b = i + num
 if len(lst[a:b])<num:
 break
 rst.append(tuple(lst[a:b]))
 return rst

Example:

>>> lst = np.array([10, 11, 12, 13, 26, 28])
>>> slice_list(lst,4)
[(10, 11, 12, 13), (11, 12, 13, 26), (12, 13, 26, 28)]
added 87 characters in body
Source Link
Jack
  • 171
  • 1
  • 13

My function needs two params(a,b) and if...break, which seems redundant. Can it be made prettier?

def slice_list(lst,num):
 rst = []
 for i,_ in enumerate(lst):
 a = i
 b = i + num
 if len(lst[a:b])<num:
 break
 rst.append(tuple(lst[a:b]))
 return rst"""

Given a list or Numpy array, get consecutive tuples based on specific window. """ rst = [] for i,_ in enumerate(lst): a = i b = i + num if len(lst[a:b])<num: break rst.append(tuple(lst[a:b])) return rst

Example:

>>> lst = np.array([10, 11, 12, 13, 26, 28])
>>> slice_list(lst,4)
[(10, 11, 12, 13), (11, 12, 13, 26), (12, 13, 26, 28)]

My function needs two params(a,b) and if...break, which seems redundant. Can it be made prettier?

def slice_list(lst,num):
 rst = []
 for i,_ in enumerate(lst):
 a = i
 b = i + num
 if len(lst[a:b])<num:
 break
 rst.append(tuple(lst[a:b]))
 return rst

Example:

>>> lst = np.array([10, 11, 12, 13, 26, 28])
>>> slice_list(lst,4)
[(10, 11, 12, 13), (11, 12, 13, 26), (12, 13, 26, 28)]

My function needs two params(a,b) and if...break, which seems redundant. Can it be made prettier?

def slice_list(lst,num):
"""

Given a list or Numpy array, get consecutive tuples based on specific window. """ rst = [] for i,_ in enumerate(lst): a = i b = i + num if len(lst[a:b])<num: break rst.append(tuple(lst[a:b])) return rst

Example:

>>> lst = np.array([10, 11, 12, 13, 26, 28])
>>> slice_list(lst,4)
[(10, 11, 12, 13), (11, 12, 13, 26), (12, 13, 26, 28)]
Post Closed as "Not suitable for this site" by Graipher, Billal BEGUERADJ, BCdotWEB, Daniel, IEatBagels
deleted 30 characters in body; edited title
Source Link
200_success
  • 145.6k
  • 22
  • 190
  • 479
Loading
Source Link
Jack
  • 171
  • 1
  • 13
Loading
lang-py

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