Python3 Converting str with screened byte characters to str [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 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': 'существительное'}

Related

Why torch.FloatTensor([[[0,1,2],[3,4,5]],[[6,7,8],[9,10,11]]]) size is [2,2,3]? [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 2 years ago.
Improve this question
>>> ft = torch.FloatTensor([[[0,1,2],[3,4,5]],[[6,7,8],[9,10,11]]])
>>> print(ft.shape)
torch.Size([2, 2, 3])
I can't understand this result.
I think the torch size should be [2,3,2], but the result is [2,2,3].
Because
len([[[0,1,2],[3,4,5]],[[6,7,8],[9,10,11]]]) = 2
This is the first 2.
and each item inside:
len([[0,1,2],[3,4,5]]) = 2
This is the second 2.
and each item inside:
len([0,1,2]) = 3
This is the 3.

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'

Return part of string between specific character pair, in string with multiple character pairs [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
Text file or string:
SomeText1/SomeText2/SomeText3/SomeText4/SomeText5
#What I am looking for:
split_func(3, "/")
>>> SomeText3
Try:
s = "SomeText1/SomeText2/SomeText3/SomeText4/SomeText5"
# s.split("/") returns a list of strings, split at the "/"
# I.e. ["SomeText1", "SomeText2", "SomeText3", "SomeText4", "SomeText5"]
# Then take the second element (remembering that the count starts at 0
result = s.split("/")[2]

I want to plot the count of over a specific number e,g 2000 [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
ax = df_1['neighbourhood'].value_counts().plot(kind='bar', figsize=(14,8),
title="Neighbourhood that showed")
ax.set_xlabel("neighboorhood")
ax.set_ylabel("Frequency")
You can assign the result of the value_counts() to a Series and filter it as below:
count = df_1['neighbourhood'].value_counts()
ax = count[count > 2000].plot(kind='bar', figsize=(14,8), title="Neighbourhood that showed")
ax.set_xlabel("neighboorhood")
ax.set_ylabel("Frequency")

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