[Solved] ValueError: too many values to unpack (Python 2.7)

Check the output of print len(values) It has more than 5 values (which is the number of variables you are trying to “unpack” it to) which is causing your “too many values to unpack” error: username, passwordHash, startRoom, originUrl, bs64encode = values If you want to ignore the tail end elements of your list, you … Read more

[Solved] Python: How to Compare Two Lists

You can convert y to a set and then iterate over x to see if any of y is in it, like this print any(any(item in word for word in x) for item in set(y)) # True any short-circuits immediately after finding a match, so this would be very efficient. Apart from that we can … Read more

[Solved] What’s the error in this pygame program? [closed]

for event in pygame.event.get(): if event.type==QUIT: pygame.quit() sys.exit() pygame.event.get() gives you all the events that occurred since the last time you called it. This loop uses all the events that are currently available. Therefore, when interface() is called, and it tries to pygame.event.get() again, there are no more events left to check for key presses … Read more

[Solved] how do I convert the first letter of every word in a list from upper case to lower case? [duplicate]

If you have gnu sed then use: sed -i ‘s/[A-Z]/\L&/’ file [A-Z] will match first upper case letter & is back-reference of matched string by pattern (in this case single upper case letter) \L converts given back-reference to lowercase solved how do I convert the first letter of every word in a list from upper … Read more

[Solved] Writing integers into a new file

You are printing the last value only. So you are getting the result only 13.You have to write the value in the for loop. b = open(‘new’, ‘w’) for n in [4, 7, 8, 10, 6, 3, 5, 13]: if n > 5: print(n) b.write(n) 1 solved Writing integers into a new file

[Solved] Explicit Exception problem with try function

I guess you got that idea from this answer. The idea the answer was trying to convey was that you can use an exception of your choice. In reality, there is no such exception as ExplicitException. You can use any exception from the built-ins or define your own exception class. You can also except the … Read more

[Solved] how can I replace letters from each word and combine them together without function [closed]

You can you string slices like so: my_string = ‘abc ‘ ‘xyz’ my_string = my_string.split() output = my_string[1][:2] + my_string[0][2:] + ” ” + my_string[0][:2] + my_string[1][2:] print(output) Output: xyc abz If you want the string to have ‘ in between the letters you can do: output = my_string[1][:2] + my_string[0][2:] + “‘ ‘” + … Read more

[Solved] why int object is not iterable while str is into python [duplicate]

Finally i found correct answer. Reason: objects which are having __iter__ they are iterable. and we can see >>> dir(16) [‘__abs__’, ‘__add__’, ‘__and__’, ‘__class__’, ‘__cmp__’, ‘__coerce__’, ‘__delattr__’, ‘__div__’, ‘__divmod__’, ‘__doc__’, ‘__float__’, ‘__floordiv__’, ‘__format__’, ‘__getattribute__’, ‘__getnewargs__’, ‘__hash__’, ‘__hex__’, ‘__index__’, ‘__init__’, ‘__int__’, ‘__invert__’, ‘__long__’, ‘__lshift__’, ‘__mod__’, ‘__mul__’, ‘__neg__’, ‘__new__’, ‘__nonzero__’, ‘__oct__’, ‘__or__’, ‘__pos__’, ‘__pow__’, ‘__radd__’, ‘__rand__’, ‘__rdiv__’, … Read more

[Solved] python code for power ball lottery [closed]

import random as r def Powerball(): result = [] for i in range(5): number = r.randint(1,69) while (number in result): number = r.randint(1,69) result.append(number) result.sort() result.append(r.randint(1,26)) return result if __name__ == ‘__main__’: result = Powerball() print result This code returns first five unique random numbers from 1 to 69 in ascending order followed by a … Read more

[Solved] Python. Function testing using Nose

In this .py file you should write import nose.tools as nt from checkers import is_triangle def test_is_triangle(): # Define test_a, test_b, and test_c here such that they should produce a # return value of False. nt.assert_false(is_triangle(test_a, test_b, test_c)) # Redefine test_a, test_b, and test_c here such that they should produce a # return value of … Read more