[Solved] House robber in Python Explanation

[ad_1] In this code on each for iteration doing like below: temp = last last = now now = max(temp + i, now) so this code in c++ actually looks like: last = 0; now = 0; for (int i = 0; i < num.length; i++) { temp = last; last = now; now = … Read more

[Solved] Invalid syntax python else: [closed]

[ad_1] Your indentation is all over the place – indentation should be in 4 white space blocks, and if and else statements should line up. A guide to python styling – http://legacy.python.org/dev/peps/pep-0008/#code-lay-out if os.path.isfile(‘number.txt’): print(‘ESISTE’) f = open(‘number.txt’, ‘r’) data = f.read() f.close() listOfNumber = data[0:12] if jid[0:12] in listOfNumber: print(“PRESENTE”) else: print(“DA INSERIRE”) numberAndMessage … Read more

[Solved] String intersection in Python

[ad_1] You can try something like this without importing any module : s1=’appleandgold’ s2=’appleblue’ track=[] for k in range(len(s1)): if k!=0: for ka in range(0,len(s1),k): if s1[ka:ka+k] in s2: track.append((len(s1[ka:ka+k]),s1[ka:ka+k])) print(max(track)[1]) output: apple [ad_2] solved String intersection in Python

[Solved] Python: Sort dictionary by value (equal values)

[ad_1] dictionaries are unordered (well pre 3.6 at least), instead sort the items d = {3: ‘__init__’, 5: ‘other’, 7: ‘hey ‘, 11: ‘hey’} print(sorted(d.items(),key=lambda item:(item[0].strip(),item[1]))) # output => [(3, ‘__init__’), (7, ‘hey ‘), (11, ‘hey’), (5, ‘other’)] if you really want it as a dict (for reasons i cant fathom) and you are using … Read more

[Solved] Simple head and tails bot [closed]

[ad_1] As Scott said, result is defined inside the flip function. I haven’t really used async before, but probably this will work for you. Take out the return statement Tab the following lines. elif message.content.startswith(config.prefix + ‘coinflip’): result = random.randint(0, 1) if result == 1: print(‘Heads!’) await client.send_message(message.channel, content=”Heads!”) else: print(‘Tails!’) await client.send_message(message.channel, content=”Tails!”) 1 … Read more

[Solved] Django 1.6.1 + MySQL + Apache 2.4.7 on Windows. Is it possible? [closed]

[ad_1] MySQLdb (the native driver for MySQL) is not compatible with Python3 yet; but the driver from Oracle for MySQL, called MySQL Connector/Python is compatible with Python 3. You should use the Oracle driver. django works with both. Once you have the driver installed, follow the connection section in the documentation. 1 [ad_2] solved Django … Read more

[Solved] How for loop in Python work?

[ad_1] When you iterate through a list in Python, any modifications to the list you are iterating through will have an effect on the for loop. For example, take this code: my_list = list() my_list.append(“hello”) for element in my_list: my_list.append(“hello”) This code will run forever, because my_list keeps growing in size. With your code, you … Read more

[Solved] calculating average over many files [closed]

[ad_1] I forgot almost everything about bash scripting. but I think you can do something like this. files=(file1 file2 file3 file4) for i in `seq 4` do j=$(($i-1)) f[$j]=`cat ./temp/${files[$i]} | awk ‘{print $2}’ ` done for i in `seq 0 1799` do sum=0 rowValue=0 for j in `seq 0 3` do fileContent=(${f[$j]}) rowValue=`echo ${fileContent[$i]} … Read more