[Solved] Create python dictionary from TXT file – value aggregation

No need to bother with pandas. Text files are iterable. Just open it, operate on the line (string) and fill a dictionnary. file = “font.txt” with open(file, “r”) as f: dic = dict() for line in f: x = line.strip(“\n”).split(” “) key = int(x[0].strip(“px”)) value = int(x[1]) if key not in dic.keys(): dic[key] = [value] … Read more

[Solved] How to sort python dictionary/list?

Assuming I understood your question, these should do it: for person in sorted(cat1): print(person, max(cat1.get(person))) result: ben 9 jeff 6 sam 9 then: for person in sorted(cat1, key=lambda x: max(cat1.get(x)), reverse=True): print(person, max(cat1.get(person))) result: ben 9 sam 9 jeff 6 then: for person in sorted(cat1, key=lambda x: sum(cat1.get(x))/len(cat1.get(x)), reverse=True): print(person, sum(cat1.get(person))/len(cat1.get(person))) result: ben 7.666666666666667 sam … Read more

[Solved] Custom Django login, can not compare passwords

DO NOT DO THIS. Django has a perfectly good and fully documented system for replacing the User model while keeping the authentication system, which has had several years to be tested for security vulnerabilities. Yours is not at all secure and you should not try to do it. 0 solved Custom Django login, can not … Read more

[Solved] Sorting score from text file into average

Use a dictionary with the keys as the class names and the value as a dictionary with student names as the keys and a list to store their scores as the value. Then use the json module to json.dump() the data to a file. When you want to add a new score: json.load() the file, … Read more

[Solved] How to read file on Linux server from Windows?

You will need a SFTP client to read the files. You cant directly replace the path with hostname. You should try something like paramiko for file ready. A quick sample: client= ssh_client.open_sftp() file = sftp_client.open(‘your_filename’) try: for line in file: #Do whatever you want for each line in the file finally: file.close() solved How to … Read more

[Solved] count prime number in a list

Here is my fix of your code. def count_primes_in_list(numbers): primes = [] for num in numbers: if num == 2: primes.append(num) else: is_prime = True for i in range(2, num): if num % i == 0: is_prime = False break if is_prime: print (num) primes.append(num) return len(primes) z = [4, 5, 6, 7, 8, 9, … Read more

[Solved] How do I make each line from a file list into separate variables?

first, read the file into a string line by line; then convert the string to a variable. In python, you can do the following i = 0 with open(“file.txt”, “r”) as ins: v = “var”+str(i) for line in ins: exec(v+”=’str(line)'”) i+=1 another approach is to read the lines into a list: with open(“file_name.txt”, “r”) as … Read more