[Solved] in python how to count how many times certain words appear without specifying the word [duplicate]

I have a solution using Counter for you: import collections data = “”” ——————————— Color: red/test/base person: latest ——————————— Color: red-img-tests person: latest ——————————— Color: red-zero-tests person: latest ——————————— Color: red-replication-tests person: latest ——————————— Color: blue person: latest ——————————— Color: black/red-config-img person: 7e778bb person: 82307b2 person: 8731770 person: 7777aae person: 081178e person: c01ba8a person: 881b1ad … Read more

[Solved] Open txt file in python

Notice that the names are separated by a colon(:) so add : in split() to split them and store them in multiple variables: with open(“filename.txt”) as f: for line in f : word1,word2,word3 = line.split(“:”) print(word1) print(word2) print(word3) 0 solved Open txt file in python

[Solved] python variables between functions

Working example with global variable and two windows. It uses only one mainloop() and Toplevel() to create second window. import tkinter as tk # — functions — def main(): #inform function to use external/global variable global int_var # only if you will use `=` to change value root = tk.Tk() root.title(“Root”) # change global variable … Read more

[Solved] Float comparison (1.0 == 1.0) always false

As others have stated, the problem is due to the way floating point numbers are stored. While you could try to use workarounds, there’s a better way to do this: Animation. In __init__: self.grid.opacity = 0 anim = Animation(opacity=1) anim.start(self.grid) solved Float comparison (1.0 == 1.0) always false

[Solved] os.path.isfile isn’t working as expected

Your code, as posted, works: File exists /usr/bin/python2.7 /home/surest/github/tests/test.py Enter the directory to the ISO file (or just drag the file here): /home/surest/Desktop/duties.odt /home/surest/Desktop/duties.odt <type ‘str’> True Process finished with exit code 0 Typo in filename/path /usr/bin/python2.7 /home/surest/github/tests/test.py Enter the directory to the ISO file (or just drag the file here): /home/surest/Desktop/meesa-typoed.odt /home/surest/Desktop/meesa-typoed.odt <type ‘str’> … Read more

[Solved] splitting a list into two lists based on a unique value

Use a dict and group by the first column: from csv import reader from collections import defaultdict with open(“in.txt”) as f: d = defaultdict(list) for k, v in reader(f,delimiter=” “): d[k].append(v) print(d.values()) Which will give you all the values in two separate lists: [[’25’, ’26’], [’12’, ’56’] If the data is always in two sections … Read more

[Solved] Convert string to dictionary with counts of variables [closed]

your_data # this is your data final_data = {} for line in yourdata: uid = line[“userId”] pids = line[“PageId”] if uid not in final_data : final_data[uid] = {} for pid in pids : pid = int(pid) if pid not in final_data[uid]: final_data[uid][pid]=0 final_data[uid][pid] += 1 res = [{“userId”:uid,”PageIDCount”:pids} for uid,pids in final_data.items()] I suppose you … Read more

[Solved] Given two lists of strings, find the total number of strings in the second list which contains any string in the first list as substring

This is a simple way, but I get 4: >>> sum(a in b for a in ListA for b in ListB) 4 Unless you want to be case-insensitive >>> sum(a.lower() in b.lower() for a in ListA for b in ListB) 5 As stated, though, your question is ambiguous: this method counts how many matches there … Read more

[Solved] Disable button in Tkinter (Python)

You need to unbind the event. state=”disabled”/state=DISABLED makes button disabled but it doesn’t unbind the event. You need to unbind the corresponding events to achieve this goal. If you want to enable the button again then you need to bind the event again. Like: from Tkinter import * def printSomething(event): print(“Print”) #Start GUI gui = … Read more

[Solved] Python – MySQLi parametized query with %d

Just solved it myself by using: try: query = “””SELECT * FROM `v_someview` WHERE `id` = %s LIMIT %s;””” x.execute(query,(str(id),int(l))) except Exception as ex: #some code So I’m declaring that i’m going to use a string (%s) but casting that parameter to an int(). 2 solved Python – MySQLi parametized query with %d

[Solved] I am trying to run python on cmd but i am getting this error ”” ‘py’ is not recognised as an internal or external command,operable or batch file [duplicate]

I am trying to run python on cmd but i am getting this error ”” ‘py’ is not recognised as an internal or external command,operable or batch file [duplicate] solved I am trying to run python on cmd but i am getting this error ”” ‘py’ is not recognised as an internal or external command,operable … Read more

[Solved] Python run from subdirectory

I added empty __init__.py files to Main/, A/, B/, and C/. I also put the following function in each of the .py files just so we had something to call: def f(): print __name__ In main.py, the significant function is get_module, which calls import_module from importlib. import errno from importlib import import_module import os from … Read more