“Online konvertieren Python in JavaScript” Code-Antworten

Konvertieren Sie JS in Python online

>>> import js2py
>>> f = js2py.eval_js('function f(x) {return x + x}')
>>> f(2)
4
>>> f()
nan
>>> f(f)
function f(x) { [python code] }function f(x) { [python code] }
mathiasgodwin

Online konvertieren Python in JavaScript

def TreeConstructor(strArr):
    parent = []
    child = []

    for i in strArr:
        child.append(int(i[1]))
        parent.append(int(i[3]))
    # each parent node have at most 2 children
    for k,v in Counter(parent).items():
        if v > 2:
            return False
    # each node is unique
    for k,v in Counter(child).items():
        if v > 1:
            return False
    return True

print (TreeConstructor(["(1,2)", "(2,4)", "(5,7)", "(7,2)", "(9,5)"]))
print (TreeConstructor(["(1,2)", "(3,2)", "(2,12)", "(5,2)"] ))   
4108vemula Paavana sai Kumar

Online konvertieren Python in JavaScript

def TreeConstructor(strArr):
    parent = []
    child = []

    for i in strArr:
        child.append(int(i[1]))
        parent.append(int(i[3]))
    # each parent node have at most 2 children
    for k,v in Counter(parent).items():
        if v > 2:
            return False
    # each node is unique
    for k,v in Counter(child).items():
        if v > 1:
            return False
    return True

print (TreeConstructor(["(1,2)", "(2,4)", "(5,7)", "(7,2)", "(9,5)"]))
print (TreeConstructor(["(1,2)", "(3,2)", "(2,12)", "(5,2)"] ))   
4108vemula Paavana sai Kumar

Konvertieren Sie den Online -Code JavaScript in Python

var bigint = require( 'big-integer' )

var lower = 'abcdefghijklmnopqrstuvwxyz';
var upper = lower.toUpperCase();
var numbers = '0123456789'
var ig_alphabet =  upper + lower + numbers + '-_'
var bigint_alphabet = numbers + lower

function toShortcode( longid )
{
	var o = bigint( longid ).toString( 64 )
	return o.replace(/<(\d+)>|(\w)/g, (m,m1,m2) =>
	{
		return ig_alphabet.charAt( ( m1 )
		  ? parseInt( m1 ) 
		  : bigint_alphabet.indexOf( m2 ) )
	});
}

function fromShortcode( shortcode )
{
	var o = shortcode.replace( /\S/g, m =>
	{
		var c = ig_alphabet.indexOf( m )
		var b = bigint_alphabet.charAt( c ) 
		return ( b != "" ) ? b : `<${c}>`
	} )	
	return bigint( o, 64 ).toString( 10 )
}

toShortcode(  '908540701891980503' ) // s.b. 'ybyPRoQWzX'
fromShortcode( 'ybyPRoQWzX' ) // s.b. '908540701891980503'
Foolish Fish

Ähnliche Antworten wie “Online konvertieren Python in JavaScript”

Fragen ähnlich wie “Online konvertieren Python in JavaScript”

Weitere verwandte Antworten zu “Online konvertieren Python in JavaScript” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen