[Solved] how to find first index of any number except 0 in python list? [closed]

You could use enumerate to iterate over the indices and values. Then use next to stop upon finding the first non-zero value. If StopIteration was thrown, the list contained no non-zero values, so do whatever error handling you’d like there. def first_non_zero(values): try: return next(idx for idx, value in enumerate(values) if value != 0) except … Read more

[Solved] Which of the following regular expressions can be used to get the domain name? python [closed]

You selected the correct regexp, you just have to quote it to use it in Python. You also need to call re.findall(), it’s not a string method. import re txt=”I refer to https://google.com and i never refer http://www.baidu.com” print(re.findall(r'(?<=https:\/\/)([A-Za-z0-9.]*)’, txt)) 1 solved Which of the following regular expressions can be used to get the domain … Read more

[Solved] python Regular expression [closed]

I think this is what you’re after: file = open(“demo.txt”,”r”) text = file.read() def find(info,text): match = re.findall(info + “+\w+\d+”,text) if match: print(match) else: print(“Not found!”) # This is how you call the function find(“whatever info is supposed to be”,text) 3 solved python Regular expression [closed]

[Solved] How to make a Palindrome Calculator in Python

Thank you everyone, the code I found to be the answer was this: begin = int(input(‘Enter begin: ‘)) end = int(input(‘Enter end: ‘)) palindromes = palindromes = len([i for i in range(begin, end+1) if str(i) == str(i)[::-1]]) for i in range(begin, end+1): if str(i) == str(i)[::-1]: print(i,’is a palindrome’) print(‘There are’, palindromes, ‘palindrome(s) between’, begin, … Read more

[Solved] Python 3.4 TypeError: input expected at most 1 arguments, got 3

input takes only a single string, so to concatenate instead of cake_amnt = int(input(‘How many’,cake,’would you like to make?’)) You should use format to build the string cake_amnt = int(input(‘How many {} would you like to make?’.format(cake))) Or use the + operator to perform concatenation cake_amnt = int(input(‘How many ‘ + cake + ‘ would … Read more

[Solved] How to make SendMessage unblocking?

You can’t make win32api.SendMessage() non-blocking because the underlying Windows function is blocking. Instead you can use win32api.PostMessage(), it has the same signature: import win32api, win32con print “start” win32api.PostMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, win32con.SC_MONITORPOWER, 2) print “end” 3 solved How to make SendMessage unblocking?

[Solved] Python in django Template [closed]

As already mentionned, you cannot (at least not out of the box and not without huge pain) directly embed Python code in an Django template, and as far as I’m concerned that’s a GoodThing(tm) – the “server page” model (PHP, ASP1 etc) has long proven to be a failure wrt/ maintainability. Now for the good … Read more

[Solved] Does Python include only 3 collection types?

No, Python supports more collection types. You missed the tuple, the deq, the string and bytes for example. Actually the possibilities are infinite since you can make any object a collection by implementing some special methods and also you can subclass most built-in sequence times. solved Does Python include only 3 collection types?

[Solved] Python : convert a hex string

You can use binascii.hexlify(): In [25]: strs=b’\x0f\x00\x00\x00NR09G05164\x00′ In [26]: import binascii In [27]: binascii.hexlify(strs) Out[27]: b’0f0000004e52303947303531363400′ 3 solved Python : convert a hex string