[Solved] House robber in Python Explanation

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 = max(temp … Read more

[Solved] Invalid syntax python else: [closed]

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] Python: Sort dictionary by value (equal values)

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 3.6+ … Read more

[Solved] Simple head and tails bot [closed]

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 solved … Read more

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

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 solved Django 1.6.1 + … Read more

[Solved] How for loop in Python work?

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 have … Read more

[Solved] calculating average over many files [closed]

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