[Solved] Use list of integer type in a loop in python [duplicate]

DDPT is an array of integers, as evidenced in this line: DDPT = [int(round(pt*TCV)) for pt in [.3,.5,.2]] DDPT[PT] is some integer, and you are trying to iterate through that. Hence the error. I would recommend giving your variables more descriptive names so these issues are easier to debug. edit: for num_iters in DDPT: for … Read more

[Solved] Replacing List items with Dictionary Items?

list_t = [‘a’,’b’,’a’,’c’,’d’,’b’] dictionary = {‘a’:1,’b’:2,’c’:3,’d’:4} lis=[] for i in list_t: for key in dictionary: if (i==key): lis.append(dictionary[i]) print lis 1 solved Replacing List items with Dictionary Items?

[Solved] Write a function named containsLetter that identifies all of the strings in a list that contain a specified letter and returns a list of those strings [closed]

Is this ok ? >>> def containsLetter(searchLetter, hulkLine): … return [x for x in hulkLine if searchLetter in x] … >>> containsLetter(‘i’, hulkLine) [‘like’, “i’m”] >>> Or >>> filter(lambda x: searchLetter in x, hulkLine) [‘like’, “i’m”] >>> 4 solved Write a function named containsLetter that identifies all of the strings in a list that contain … Read more

[Solved] How to had try exception to log to logger using python

I have modified your script and it’s working import os import logging import sys logging.basicConfig(filename=”log.txt”,level=logging.INFO,format=”%(asctime)s- %(message)s”,filemode=”a”) def checkfileexist(Pth,Fle): var=Pth+”https://stackoverflow.com/”+Fle try : if (var is None): logging.error(‘Path is empty’) raise Exception(“empty path”) if os.path.exists(var): logging.error(‘File found’) return (var) else: raise Exception(“File Not found”) except Exception as e: logging.error(‘Not Found file’) sys.exit() def additionvalue(a,b): return (a+b) you … Read more

[Solved] How can I take an integer input from user and store it to an array? [closed]

Try changing the last line to: print str(number) This will change the list into a printable string representation. If you want to learn more about strings and formatting, check out Chapter 7 of the Python Tutorial. Actually, the whole tutorial is pretty awesome. 🙂 EDIT: David is correct in his comment below…print converts lists to … Read more

[Solved] sklearn.metrics.roc_curve only shows 5 fprs, tprs, thresholds [closed]

This might depend on the default value of the parameter drop_intermediate (default to true) of roc_curve(), which is meant for dropping suboptimal thresholds, doc here. You might prevent such behaviour by passing drop_intermediate=False, instead. Here’s an example: import numpy as np try: from sklearn.datasets import fetch_openml mnist = fetch_openml(‘mnist_784’, version=1, cache=True) mnist[“target”] = mnist[“target”].astype(np.int8) except … Read more

[Solved] Converting binary code to DNA code [closed]

You could loop over that input in steps of two, detect the binary word and add the corresponding nucleic acid to the output. inputStr=”00011011″ # ABCD outputStr=”” for start in range(0, len(inputStr), 2): word = inputStr[start:start+2] if word == ’00’: outputStr += ‘A’ elif word == ’01’: outputStr += ‘B’ elif word == ’10’: outputStr … Read more

[Solved] Why fuction’s not returning value? [closed]

Your update2new function definitely returns something: def update2new(src_dest): print(“Hi”) fileProcess(src_dest) os.remove(‘outfile.csv’) os.remove(‘new.csv’) return src_dest But you don’t capture it in your main: def main(): print(“<——Initializing Updating Process——>”) srcFile=”abc_20160301_(file1).csv” update2new(srcFile) #the return is NOT captured here print(‘\nSuccessfully Executed [ {}]……’.format(str(srcFile)),end=’\n’) print (“OK”) Change it to: def main(): print(“<——Initializing Updating Process——>”) srcFile=”abc_20160301_(file1).csv” srcFile = update2new(srcFile) #get the … Read more

[Solved] Does anyone have any idea what is wrong with this code?

password = str(input(“Enter your password then press enter: “)) while not 6 < len(password) < 12 : password = str(input(“Enter a password that is between 6 and 12 characters: “)) The first line gets the user’s input as a string without a newline character. The second and third lines act as a do-while loop, asking … Read more

[Solved] How to configure and use MySQL with Django? [closed]

You can easily install xampp first from https://www.apachefriends.org/download.html (Follow these steps for xampp installation.) Then follow the instructions as: Install and run xampp from http://www.unixmen.com/install-xampp-stack-ubuntu-14-04/, then start Apache Web Server and MySQL Database from the GUI. You can configure your web server as you want but by default web server is at http://localhost:80 and database … Read more

[Solved] Json output s — just print the output withou u

Depends on what you want to do when there’s more than one value in change[‘Errors’]. Currently the value is a list of one element (u’DELETED’). If you want to print just the text, you need: print error[0] But maybe just in case it would be better to do: print u’, ‘.join(error) 2 solved Json output … Read more