[Solved] How to split chinese and english word once only?

One of the option is just to split before the first English character and take the 1st and 2nd group inputstring = ‘小西 – 杏花 Siu Sai – Heng Fa’ a = re.split(r'([a-zA-Z].*)’, inputstring) >>>[‘小西 – 杏花 ‘, ‘Siu Sai – Heng Fa’, ”] Another way to do this without an empty string is to … Read more

[Solved] __init__.py”, line 92, in raise RuntimeError(“Python 3.5 or later is required”)

You need to tell Visual Studio Code which python interpreter to use. By default, it’s going to use the system python.In your case, it got the Python 3.4.4 version. Open the command palette and select Python: Select Interpreter. Then select the appropriate one from the list: You can also manually set this by adding this … Read more

[Solved] Traverse Non-Binary Tree [closed]

def traverse(tree_of_lists): for item in tree_of_lists: if isinstance(item, list): for x in traverse(item): yield x else: yield item This is the “basic” solution — can run in Python 2.7 and gives you an iterable that you can simply loop on. (In recent Python 3.* versions you’d use yield from item instead of the inner for … Read more

[Solved] Regex for this date format?

Split the task into 3 parts. First, a number in the range of 1-31 (tutorial), then a list of possible values for the month, and then two numbers. \b([1-9]|[12][0-9]|3[01])-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d{2})\b Regex101 Demo 3 solved Regex for this date format?

[Solved] Try / Except Statements in python [closed]

inventory = {847502: [‘APPLES 1LB’, 1.99, 50], 847283: [‘OLIVE OIL’, 10.99, 100], 839529: [‘TOMATOS 1LB’, 1.29, 25], 483946: [‘MILK 1/2G’, 3.45, 35], 493402: [‘FLOUR 5LB’, 2.99, 40], 485034: [‘BELL PEPPERS 1LB’, 1.35, 28], 828391: [‘WHITE TUNA’, 1.69, 100], 449023: [‘CHEESE 1/2LB’, 4.99, 15]} while True: try: upc_input = int(input(‘Enter a UPC number: ‘)) break except … Read more

[Solved] PYTHON codes with a lesson from a book [closed]

Briefly: cities is instantiated as a dictionary, and some key/value are inserted here. Both key and values are string for CA -> San Francisco, MI -> Detroit, etc. etc. a function named find_city is defined, it takes two input parameters (themap and state); to the cities dictionary is added another key/value, where key is the … Read more

[Solved] How to access a part of an element from a list?

You need to iterate on the list and retrieve the good properties on each. values = [[Decoded(data=b’AZ:HP7CXNGSUFEPZCO4GS5RQPY6XY’, rect=Rect(left=37, top=152, width=94, height=97))], [Decoded(data=b’AZ:9475EFWZCNARPEJEZEMXDFHIBI’, rect=Rect(left=32, top=191, width=90, height=88))], [Decoded(data=b’AZ:6ECWZUQGEJCR5EZXDH9URCN53M’, rect=Rect(left=48, top=183, width=88, height=89))], [Decoded(data=b’AZ:XZ9P6KTDGREM5KIXUO9IHCTKAQ’, rect=Rect(left=73, top=121, width=91, height=94))]] datas = [value[0].data for value in values] # list of encoded string (b”) datas = [value[0].data.decode() for value in … Read more

[Solved] How can I increment array with loop?

You mean to do: while iterations < itemsInListOne: listOne[iterations] = float(listOne[iterations]) + 1 Note that you needed to convert it to a float before adding to it. Also note that this could be done more easily with a list comprehension: listOne = [float(x) + 1 for x in listOne] solved How can I increment array … Read more

[Solved] What i did wrong in my python function?

Well, you got what you told to print! board is a list of list of strs, so board[i] must be a list of strs, and when you write print(board[i]), you get a list! You may need to write this: print(”.join(board[i])) solved What i did wrong in my python function?