[Solved] Find password by username

I am supposing your csv will be like this: user1, hash_pass_u1 user2, hash_pass_u2 user3, hash_pass_u3 … Just one note before the solution. You are importing the CSV module of Python and you did not use it in your code, such a silly import, just use it. The solution is simple import csv file=”yourcsv.csv” found = … Read more

[Solved] How do I split a text file into multiple text files by 25 lines using python? [closed]

You could try chunking every 25 lines, then write them each out to separate files: def chunks(l, n): “””Chunks iterable into n sized chunks””” for i in range(0, len(l), n): yield l[i:i + n] # Collect all lines, without loading whole file into memory lines = [] with open(‘FileA.txt’) as main_file: for line in main_file: … Read more

[Solved] How do you find the number of letters in a word in python? [duplicate]

You’re looking for the len method, which works on any object with a definable length: >>>test_string = “Hello” Hello >>>len(test_string) 5 For a string, it will treat the string as a list of characters. This means “Hello” has 5, but “Hello ” would have 6, and “Hello World!” would have 12. docs: https://docs.python.org/3/library/functions.html#len solved How … Read more

[Solved] Expanding the inline python code [closed]

First the final answer, which is really a one-liner. Some explanations follow a = [88, 24, 128, 3] [i + 1 for i, x in enumerate(“”.join(bin(n + 256)[3:] for n in a)) if x == “1”] This yields [2, 4, 5, 12, 13, 17, 31, 32] First transformation: def dec2bin(a): return [int(x) for x in … Read more

[Solved] How can I implement a word to PDF conversion in python without importing any libraries? [closed]

Code it from scratch. If you’re not going to use an external library, that is by definition pretty much your only option. You’ll want to become an expert in the formal specifications for both PDF and MS Word. Given the complexity and history of each of those, I expect a senior developer will want 6-12 … Read more

[Solved] Concatenate string & list [duplicate]

You can use str.format, and str.join to get your required output. Ex: fruits = [‘banana’, ‘apple’, ‘plum’] mystr=”i like the following fruits: \n\n{}”.format(“\n”.join(fruits)) print(mystr) Output: i like the following fruits: banana, apple, plum 3 solved Concatenate string & list [duplicate]

[Solved] How to add elements in list in for loop? My output is [1,1,1] instead of [1,4,5] [closed]

Your version does not work because index always get the first match. And this code is way cleaner and shorter: def search_for_string(lists,str1): list2=[] for index, value in enumerate(lists): if value==str1: lists[index] = ‘xxxxx’ list2.append(index) return list2 sample_list = [“artichoke”, “turnip”, “tomato”, “potato”, “turnip”, “turnip”, “artichoke”] print(search_for_string(sample_list, “turnip”)) Output : C:\Users\Documents>py test.py [1, 4, 5] solved … Read more

[Solved] Matrix, how to solve? [closed]

import random n = int(input(‘Введите кол-во столбцов матрицы: ‘)) #columns m = int(input(‘Введите кол-во строк матрицы: ‘)) #rows matrix = [[random.randrange(0, 10) for y in range(n)] for x in range(m)] for i in range(m): for j in range(n): print(matrix[i][j], end = ” “) print() max_x = 0 for i in range(m): for j in range(n): … Read more

[Solved] How to simulate saturations and thresholds with Scipy?

You could try Steven Masfaraud’s block module simulator (BMS). As of August 2016 it has nonlinear block elements for Saturation, Coulomb, Dead Zone, and Hysteresis. Here’s a link to one of his examples. The other option on this Quora post is PyLinX. It looks like SciPySim may no longer be under development, from this link … Read more

[Solved] Writing JSON in Python

json.dump() takes two arguments, the Python object to dump and the file to write it to. Make your changes first, then after the loop, re-open the file for writing and write out the whole data object: with open(“app.json”) as json_data: data = json.load(json_data) for d in data[’employees’]: d[‘history’].append({‘day’: 01.01.15, ‘historyId’: 44, ‘time’: 12.00}) with open(“app.json”, … Read more

[Solved] What does this mean? == “”

This is reading the file line-by-line, and finishing at the first empty line, meaning the end of the file. breakexits the while True;loop It’s horrible code though; cases where you actually need to manually code a loop like this a pretty rare in python. More succinct/pythonic would be something like: for buffer in fp.readlines(): print(buffer) … Read more