// js
> f = (...args) => args.length
> f(1, 2, [1, 2])
3
#py
// js
> f = (...args) => args.length
> f(1, 2, [1, 2])
3
#py
> var object = { 'a': 1, 'b': '2', 'c': 3 }; | |
> _.omit(object, ['a', 'c']); | |
{ 'b': '2' } | |
> object = { 'a': [{ 'b': 2 }, { 'd': 4 }] } | |
> other = { 'a': [{ 'c': 3 }, { 'e': 5 }] } | |
> _.merge(object, other); | |
{ 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] } | |
> a = {b: [{a : 1}, {b: 12}]} | |
> b = {b: [{b: 67}]} |
# py
> a = 1
> b = 'a'
> eval(b)
1
import numpy as np | |
import pandas as pd | |
> lbls = ['a', 'b', 'c'] # or np.array | |
> data = [123, 423, 456] | |
> d = {} | |
> for i in np.arange(len(lbls)): | |
> d[lbls[i]] = data[i] | |
> pd.Series(data = data) |
// js
> keys = [0, 1, 2]
> values = ['a', 'b', 'c']
> obj = {}
> keys.forEach((key, i) => obj[key] => values[i] )
> obj
{0: 'a', 1:'b', 2:'c'}
// js
> [1, 2, 3, 4, 5].slice(0, 1) // from index 0 inclusive to index 1 exclusive
[1]
> [1, 2, 3, 4, 5].slice(1, -1)
[2, 3, 4]
// arrays are objects
// js
> ((...a) => a.some(_ => _)) ("", '', 0, false, null, NaN, undefined)
false
> ["", '', 0, false, null, NaN, undefined].some(Boolean)
false
form_data = {} | |
// evaluating the args out of the if-then clause enables them to be available | |
// inside the if-then body. They are intended to be evaluated on whether they're | |
// empty or not, but evaluating them on the if-then condition would not let all | |
// args be evaluated if at least one but the last was not empty. | |
lastEvolutionsEdit = {{admin_edit_evolution_txt.text}} | |
lastRoleEdit = {{admin_edit_role_txt.text}} | |
lastTrainEdit = {{admin_edit_training_txt.text}} |
# py
> def f(a, b = 1):
> return a + b
> print f(1)
2
# python
if True:
print 'always'
elif False:
print 'never'
else:
print 'never ever'