[Solved] convert js function to Python [closed]

It’s more straightforward than you think: def getCardinalDirection(angle): directions = [‘↑ North’, ‘↗ North East’, ‘→ East’, ‘↘ South East’, ‘↓ South’, ‘↙ South West’, ‘← West’, ‘↖ North West’] return directions[round(angle / 45) % 8] # round() is a built-in function Example output: >>> getCardinalDirection(50) ‘↗ North East’ >>> getCardinalDirection(220) ‘↙ South West’ >>> … Read more

[Solved] how to print a string who contains variables, the string is contained is .json file? [closed]

I think you should develop more on your fundamentals, and try out your own code before asking a question here. I guess what you are trying to achieve can be done like this. import json with open(“example.json”, “r”) as f: json_content = json.load(f) message = json_content[“message”] variable = “var” print(message.format(variable=variable)) # prints # this is … Read more

[Solved] how to make the width and height x2 using python Regular

Don’t use regular expressions to parse HTML. Use BeautifulSoup >>> from BeautifulSoup import BeautifulSoup >>> ht=”<html><head><title>foo</title></head><body><p>whatever: <img src=”https://stackoverflow.com/questions/5878079/foo/img.png” height=”111″ width=”22″ /></p><ul><li><img src=”foo/img2.png” height=”32″ width=”44″ /></li></ul></body></html>” >>> soup = BeautifulSoup(ht) >>> soup <html><head><title>foo</title></head><body><p>whatever: <img src=”https://stackoverflow.com/questions/5878079/foo/img.png” height=”111″ width=”22″ /></p><ul><li><img src=”foo/img2.png” height=”32″ width=”44″ /></li></ul></body></html> >>> soup.findAll(‘img’) [<img src=”https://stackoverflow.com/questions/5878079/foo/img.png” height=”111″ width=”22″ />, <img src=”foo/img2.png” height=”32″ width=”44″ />] >>> for … Read more

[Solved] Regex to find if a string contains all numbers 0-9 be it in any order [duplicate]

This solution can handle all sorts of strings, not only numeric characters. s1 = ‘ABC0123091274723507156XYZ’ # without 8 s2 = ‘ABC0123091274723507156XYZ8′ len(set(“”.join(re.findall(r'([\d])’, s1)))) == 10 # False len(set(“”.join(re.findall(r'([\d])’, s2)))) == 10 # True How it works: Find all digits in the string with regex findall. Join all matches to one string and get unique characters … Read more

[Solved] How to use the variable from the python in rpy2?

First, make two lists from your database. Something like: cursor = con.cursor() cursor.execute(“SELECT * FROM traffic”) #Retrieves data from SQL rows = cursor.fetchall() Month = list() Traffic = list() for row in rows: Month.append(row[‘Month’]) # guesswork – what does a row look like? Traffic.append(row[‘Traffic’]) Then, now you have two python lists, you can make a … Read more

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

>>> 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′ 1 solved Coverting a python list into string with comma separated in efficient way [closed]