Double assignment in python -


please see code here

move_from, move_to = [         (item['path'], prev_item['path']),         (prev_item['path'], item['path']),     ][item['op'] == 'add'] 

what assigned move_from , move_to. looks double assignment, don't see 2 on right (i non python programmer) trying port javascript, how like?

thanks.

this

[ (item['path'], prev_item['path']), (prev_item['path'], item['path']), ] 

is python list. first (0) item

(item['path'], prev_item['path']) 

and second (1) is

(prev_item['path'], item['path']) 

the boolean here

[item['op'] == 'add'] 

evaluates true of false ( 1 or 0 ) 1 of items chosen.

for example, if item['op'] equal 'add', result is

move_from, move_to = prev_item['path'], item['path'] 

edit: asked js code. might it. note i've assumed variables global since don't know in context use this.

string.prototype.rsplit = function(sep, maxsplit) {     var split = this.split(sep);     return maxsplit ? [ split.slice(0, -maxsplit).join(sep) ].concat(split.slice(-maxsplit)) : split; }  function _optimize_using_move(prev_item, item) {     prev_item['op'] = 'move';     if (item['op'] == 'add') {         prev_item['from'] = prev_item['path'];         prev_item['path'] = item['path'];     } else {         var parts = move_from.rsplit('/', 1);         head = parts[0];         move_from = parts[1];         move_from = int(item['path']) - 1;         prev_item['from'] = head + '/' + item['path'];         prev_item['path'] = prev_item['path'];     } } 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -