[Solved] How can i change the position of substring within a string in Python?

You can split the string into a list of substrings: >>> s=”xxxxxxxx,yyyyyyyyyyyy,zzzzzzzzz” >>> parts = s.split(‘,’) >>> parts [‘xxxxxxxx’, ‘yyyyyyyyyyyy’, ‘zzzzzzzzz’] Then you can re-order: >>> reordered = parts[0] + parts[2] + parts[1] >>> reordered [‘xxxxxxxx’, ‘zzzzzzzzz’, ‘yyyyyyyyyyyy’] And rejoin: >>> ‘,’.join(reordered) ‘xxxxxxxx,zzzzzzzzz,yyyyyyyyyyyy’ 1 solved How can i change the position of substring within a … Read more

[Solved] How do you get the number in nested loop? [closed]

The code needs to go through 11 inner loop iterations and 3 outer loop iterations to meet the condition of the country being ‘Brazil’ and the capital city being ‘Brasilia’. The print statement line is only executed the once during the entire script when those conditions are met. At the point of this line being … Read more

[Solved] Want genuine suggestion to build Support Vector Machine in python without using Scikit-Learn [closed]

You can implement a simple linear SVM with numpy only like below. BTW, please google before you ask question next time. There are lots of resources and tutorial online. import numpy as np def my_svm(dataset, label): rate = 1 # rate for gradient descent epochs = 10000 # no of iterations weights = np.zeros(dataset.shape[1]) # … Read more

[Solved] why here Twice run program

Issues with Code : Object creation is not correct for password class. also argument self is not passed to class method . Fixed Code class password: def pas1(self): pas = [] tedad = int(input(‘how many do you have information ? : ‘)) for i in range(1,tedad): b=input(‘enter : ‘) pas.append(b) print(‘this is your pas —> … Read more

[Solved] Python split unicode characters and words

I’ll assume that your string is always of the form “<emoticon><alphabets>”. I’ll then splice the string. # Count number of alphabets first num = [c.isalpha() for c in string].count(True) # Splice string based on the result s1 = string[:-num] s2 = string[-num:] 5 solved Python split unicode characters and words

[Solved] Python HTML parsing from url [closed]

From Python HTMLParser Documentation: from HTMLParser import HTMLParser # create a subclass and override the handler methods class MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): print “Encountered a start tag:”, tag def handle_endtag(self, tag): print “Encountered an end tag :”, tag def handle_data(self, data): print “Encountered some data :”, data # instantiate the parser and fed it … Read more

[Solved] I am trying to get my python twitter bot to tweet every 30 minutes on the hour. What should I do? [closed]

So using datetime you can actually get the minutes like this: from datetime import datetime time = datetime.now() minutes = time.minute Or in one line: from datetime import datetime minutes = datetime.now().minute Now that you have the minutes, the if statement can be simplified down, because you don’t look at the hour. if minutes == … Read more

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

[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’: ‘существительное’} 2 solved … Read more