Python join 2 char into the same short [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I would like to do 2 char into a short.
I want to do that (c syntax):
short var = (msg[4:5]<<8) | (msg[5:6])
algo:
ord(msg[4:5) = 105 -> 0b1101001
ord(msg[5:6) = 135 -> 0b10000111
var = 0b1101001 <<8 eq 0b1101001 00000000 eq 0x6900
var |= 0b10000111 eq 0b1101001 10000111 eq 0x6987
var = 27015
So i want as result the a numeric value
If you have any solution...
Thanks

(ord(msg[4])<<8) + ord(msg[5])

Related

Why encode()/decode() function can't output right result in Charm-crypto? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 hours ago.
Improve this question
I used integergroup in charm-crypto as building block, and used encode_as_group_element() and decode_from_group_element() to conversion element between int and Integer element mod N, but I can't get right result.
For example,
a = 15651 mod 62939
print(a)
b = decode_from_group_element(a, group)
print(b)
c = encode_as_group_element(b, group)
print(c)
>>>>15651 mod 62939
>>>>34
>>>>62648 mod 62939

How to return false when a punctuation is present in an input [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
# no periods, spaces or puctuation marks
punctuation_not_wanted = [".","!", " " "/"]
for punctuation_not_wanted in s:
if punctuation_not_wanted in s:
return false
You can compare them as sets. If they have same symbols, their intersection (&) will have this same symbols and will converts to True for if statement.
if set(punctuation_not_wanted) & set(s):
return False
all([(c not in s) for c in punctuation_not_wanted])

Coverting a python list into string with comma separated in efficient way [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a list of acc nos:
list1 = ['1234','3456','2345','5543','1344','5679','6433','3243','0089']
Output I need is a string:
print(output): '1234','3456','2345','5543','1344','5679','6433','3243','0089'
You can join all the values with ',' and then adding a ' before and after the string like this:
"'{0}'".format("','".join(list1))
>>> list1 = ['1234','3456','2345','5543','1344','5679','6433','3243','0089']
>>> print(','.join(["'{0}'".format(s) for s in list1]))
'1234','3456','2345','5543','1344','5679','6433','3243','0089'

Python3 Converting str with screened byte characters to str [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
How to convert this field from database
to
or to
[EDIT]The question was updated and the below was answered based on the original question.
if you fix your input var1 then you can do something like this:
var1 = '{"text":"tool","pos":"\\xd1\\x81\\xd1\\x83\\xd1\\x89\\xd0\\xb5\\xd1\\x81\\xd1\\x82\\xd0\\xb2\\xd0\\xb8\\xd1\\x82\\xd0\\xb5\\xd0\\xbb\\xd1\\x8c\\xd0\\xbd\\xd0\\xbe\\xd0\\xb5"}'
md = {}
for e in var1[1:-1].split(','):
md[e.split(':')[0][1:-1]] = e.split(':')[1][1:-1]
md['pos'] = (bytes.fromhex(''.join([h for h in md['pos'].split('\\x')]))).decode('utf-8')
print(md)
output:
{'text': 'tool', 'pos': 'существительное'}

Recursive sequence $x_n = \sqrt{2}$, $x_{n+1} = \sqrt{2x_n}$ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How would I create a script it in python late the values from the recursive sequence:
$x_1 = \sqrt{2}$, $x_{n+1} = \sqrt{2x_n}$ http://www.sciweavers.org/upload/Tex2Img_1392861864/render.png
X = [sqrt(2)]
for i in range(1,10):
X.append(sqrt(2*X[i-1]))
Here is a slow solution. Assuming n is >=1
import math
def recursive(n):
if n = 1:
math.sqrt(2)
return math.sqrt(2*recursive(n-1))

Categories