[Solved] Hackerrank Code not working [closed]

There are several things wrong with your program. First the insert method doesn’t do what you seem to think it does. list.insert(i, x) Insert an item at a given position. The first argument is the index of the element before which to insert, so a.insert(0, x) inserts at the front of the list, and a.insert(len(a), … Read more

[Solved] Can we develop a Python API which wraps R code [closed]

As mentioned in an earlier post, things that are not easy in R can be relatively simple in other languages. Another example would be connecting to Amazon Web Services. In relation to s3, although there are a number of existing packages, many of them seem to be deprecated, premature or platform-dependent. (I consider the cloudyr … Read more

[Solved] How to get unigrams (words) from a list in python?

Aren’t those strings containing a single word, e.g. “evaporation” & “sunlight” unigrams? It seems to me that you want to retain the unigrams, not remove them. You can do that using a list comprehension: list1 = [‘water vapor’,’evaporation’,’carbon dioxide’,’sunlight’,’green plants’] unigrams = [word for word in list1 if ‘ ‘ not in word] >>> print … Read more

[Solved] How to match the bundle id for android app?

You could try: r’\?id=([a-zA-Z\.]+)’ For your regex, like so: def get_id(toParse) regex = r’\?id=([a-zA-Z\.]+)’ x = re.findall(regex, toParse)[0] return x Regex – By adding r before the actual regex code, we specify that it is a raw string, so we don’t have to add multiple backslashes before every command, which is better explained here. ? … Read more

[Solved] Python Regular Expression from File

This will return the elements you want: import re s=””‘journey (a,b) from station south chennai to station punjab chandigarh journey (c,d) from station jammu katra to city punjab chandigarh journey (e) from station journey (c,d) from station ANYSTRING jammu katra to ANYSTRING city punjab chandigarh ”’ matches_single = re.findall(‘journey (\([^,]+,[^,]+\)) from (\S+ \S+\s{0,1}\S*) to (\S+ … Read more

[Solved] Finding repeated lines in Python [duplicate]

I assume you have read in the lines and stored them in an array lines Then, set(lines) gives you a set that contains all unique lines. If every line is unique the length of lines and set(lines) will be the same. Ergo: if len(lines) == len(set(lines)): print ‘all lines are unique’ else: print ‘not all … Read more

[Solved] Delete items from list of list

You need to loop over b, either setting each element to the empty list or deleting the contents of that element: for i in xrange(len(b)): b[i] = [] or for i in xrange(len(b)): del b[i][:] 3 solved Delete items from list of list

[Solved] how to modify the output [closed]

While this code is not pretty to do what your’re looking to do you need to change these lines if num>0: l+='”‘+ str(k) + ‘”=’ + str(num)+’ ‘ True if True: lst+=[l] If you change it to something like if num>0: l+='”‘+ str(k) + ‘”=’ + str(num)+’ ‘ flag = True if flag: lst+=[l] and … Read more