# Rewriting this function from python to julia

6 messages
Open this post in threaded view
|

## Rewriting this function from python to julia

 `return "".join(chr(ord(a)^ord(b)) for a,b in zip(s,t))`Now I know that chr = Char, ord = Int, and zip = tuple in julia. But while using this in that context I get a load error saying the I'm missing a ", or )"`function xorStrings(s,t)        global xorStr = join(Char(Int(a)^Int(b)) for a,b in tuple(s,t)exit`
Open this post in threaded view
|

## Re: Rewriting this function from python to julia

 ^ isn't xor in Julia, it's exponentiation. You can use infix \$ instead.On Mon, Nov 7, 2016 at 3:02 PM, Jacob Yates wrote:`return "".join(chr(ord(a)^ord(b)) for a,b in zip(s,t))`Now I know that chr = Char, ord = Int, and zip = tuple in julia. But while using this in that context I get a load error saying the I'm missing a ", or )"`function xorStrings(s,t)        global xorStr = join(Char(Int(a)^Int(b)) for a,b in tuple(s,t)exit`
Open this post in threaded view
|

## Re: Rewriting this function from python to julia

 I know ^ is an exponent. The whole function is meant to xor strings the strings end up being the variables s and t On Nov 7, 2016 15:12, "Stefan Karpinski" <[hidden email]> wrote:^ isn't xor in Julia, it's exponentiation. You can use infix \$ instead.On Mon, Nov 7, 2016 at 3:02 PM, Jacob Yates wrote:`return "".join(chr(ord(a)^ord(b)) for a,b in zip(s,t))`Now I know that chr = Char, ord = Int, and zip = tuple in julia. But while using this in that context I get a load error saying the I'm missing a ", or )"`function xorStrings(s,t)        global xorStr = join(Char(Int(a)^Int(b)) for a,b in tuple(s,t)exit`
Open this post in threaded view
|

## Re: Rewriting this function from python to julia

 You also need parens around (a,b):julia> xorStrings(s,t) = join(Char(Int(a) \$ Int(b)) for (a,b) in zip(s,t))xorStrings (generic function with 1 method)julia> xorStrings("foo","bar")"\x04\x0e\x1d"julia> xorStrings("foo",ans)"bar"On Mon, Nov 7, 2016 at 3:17 PM, blm22 wrote:I know ^ is an exponent. The whole function is meant to xor strings the strings end up being the variables s and t On Nov 7, 2016 15:12, "Stefan Karpinski" <[hidden email]> wrote:^ isn't xor in Julia, it's exponentiation. You can use infix \$ instead.On Mon, Nov 7, 2016 at 3:02 PM, Jacob Yates wrote:`return "".join(chr(ord(a)^ord(b)) for a,b in zip(s,t))`Now I know that chr = Char, ord = Int, and zip = tuple in julia. But while using this in that context I get a load error saying the I'm missing a ", or )"`function xorStrings(s,t)        global xorStr = join(Char(Int(a)^Int(b)) for a,b in tuple(s,t)exit`