[Solved] Coding a function in python wihch count the number of occurances [closed]

Use the collections module to use the Counter function. Such as: import collections def carCompt(*args): return collections.Counter(“”.join(map(str.upper, args))) This will return {‘A’:5, ‘D’:1, ‘E’:3, ‘H’:2, ‘L’:1, ‘N’:1, ‘O’:1, ‘P’:2, ‘R’:2, ‘S’:1, ‘X’:1} If you want it to be case sensitive then leave it like: import collections def carCompt(*args): return collections.Counter(“”.join(args)) which will return {‘a’: 4, … Read more

[Solved] How to print specific strings in python? [closed]

You could use a regular expression: import re string = “””736.199070736: LOG_MOD_L0_RECEIVE_TXBRP_CONTROL(0, 0x0075007f, 0x005500dd, 0x000a00f5)””” result = re.search(r’\(.*\)’, string) # matches anything between parenthesis result.group() ‘(0, 0x0075007f, 0x005500dd, 0x000a00f5)’ That gives you the data as a string. 2 solved How to print specific strings in python? [closed]

[Solved] Running total for list of dict

I assumed date is increasing order. # store values tot = {} # the last date date0 = Dict1[-1][‘date’] # easier to work from back, i found for line in Dict1[-1::-1]: date, name, qty = [line[x] for x in ‘date’, ‘name’, ‘qty’] # add the value to all subsequent days for d in range(date, date0+1): … Read more

[Solved] How do i get a list of all the urls from a website with python? [closed]

Since all the links have a class in common (class=”blue”), you can select all the web elements using this code, and then get the “href” attribute values: elements = driver.find_elements_by_class_name(‘blue’); urls = [elements.get_attribute(‘href’) for elements in elements] I recommend this site if you want to learn more about Selenium Python : Learn to Locate Elements … Read more

[Solved] How do you read a file then output the integers as ‘1’ in txt

This should solve your problem. Input file: 1234 5678 Code: with open(‘a.txt’) as if1: for everyline in if1: everylineactual = everyline.rstrip(‘\n’) everylineactual = “‘,'”.join(everylineactual) everylineactual = f”‘{everylineactual}’\n” with open(‘b.txt’,’a’) as of: of.write(everylineactual) Output file: ‘1’,’2′,’3′,’4′ ‘5’,’6′,’7′,’8′ 0 solved How do you read a file then output the integers as ‘1’ in txt

[Solved] Re-usable function [closed]

You could define aroot as a parameter, so you would have to pass your root in every time you call the function, if that is what you mean? def SetERP(ArticleN, ERPn, aroot): for ERPRecord in aroot.iter(‘part’): if ERPRecord.get(‘P_ARTICLE_ORDERNR’) == ArticleN: ERPRecord.set(‘P_ARTICLE_ERPNR’, ERPn) 2 solved Re-usable function [closed]

[Solved] How to split a python dictionary for its values on matching a key

from itertools import product my_dict = {‘a’:1, ‘chk’:{‘b’:2, ‘c’:3}, ‘e’:{‘chk’:{‘f’:5, ‘g’:6}} } def process(d): to_product = [] # [[(‘a’, 1)], [(‘b’, 2), (‘c’, 3)], …] for k, v in d.items(): if k == ‘chk’: to_product.append([(k2, v2) for d2 in process(v) for k2, v2 in d2.items()]) elif isinstance(v, dict): to_product.append([(k, d2) for d2 in process(v)]) else: … Read more

[Solved] How do I make Selenium click on this button?

There are two buttons are present with the same xpath. if you want to click first button then use below code wait = WebDriverWait(browser, 10) button= wait.until(EC.element_to_be_clickable((By.XPATH,'(//button[@class=”Button”])[1]’))) button.click() if you want to click the second button then use below code wait = WebDriverWait(browser, 10) button= wait.until(EC.element_to_be_clickable((By.XPATH,'(//button[@class=”Button”])[2]’))) button.click() solved How do I make Selenium click on … Read more

[Solved] How to remove the background of an object using OpenCV (Python) [closed]

You mean this? : import cv2 import numpy as np img = cv2.imread(“image.jpg”) hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) mask = cv2.inRange(hsv, (0, 0, 0), (75, 255, 255)) imask = mask > 0 green = np.zeros_like(img, np.uint8) green[imask] = img[imask] cv2.imwrite(“result.png”, green) Output 1 solved How to remove the background of an object using OpenCV (Python) [closed]