[Solved] how to make a new line before a digit in a string [closed]

Use regex a=”HOW TO COOK RICE – Chapter 1: 1 rinse water once 2 add one and a half cup of water for every cup of rice 3 cover the pot and simmer” idx=[i.start() for i in re.finditer(‘(\d{1,} \w{1,})’, a)] if idx: print(a[:idx[0]]) else: print(a) for i,index in enumerate(idx): if not i==len(idx)-1: print(a[index:idx[i+1]]) else: print(a[idx[i]:]) … Read more

[Solved] C# List sorting with multiple range

you can use the Sort overload accepting a Comparison. This should work: public static int MyCompare(double x, double y) { if (x >= 0.0 == y>=0.0) // same sign, compare by absolute value return Math.Abs(x).CompareTo(Math.Abs(y)); if (x < 0.0) return 1; return -1; } usage: var list = new List<double>(); // fill your list // … Read more

[Solved] Python Form a List based from the values in dictionary

dictA = {“f1” : [“m”], “f2” : [“p”,”y”,”o”,”a”,”s”,”d”,”f”,”g”], “f3” : [“w”,”t”], “f5” : [“z”,”x”], “f6” : [“c”,”v”]} result = [] limit_size = 3 values_list = [] for values in dictA.itervalues(): values_list.append(len(values)) for i in range(0,max(values_list)): keys = list(dictA.keys()) count = 0 while count < len(keys): try: result.append(dictA[keys[count]][i]) except IndexError: dictA.pop(keys[count]) count = count + 1 … Read more

[Solved] Convert a char list list into a char string list in OCAML

Here is a very compact implementation: let to_str_list = List.map (fun cs -> String.concat “” (List.map (String.make 1) cs)) It looks like this when your call it: # to_str_list [[‘h’;’e’;’l’;’l’;’o’];[‘w’;’o’;’r’;’l’;’d’]];; – : string list = [“hello”; “world”] Update If you want to suppress empty strings at the outer level you can do something like this: … Read more

[Solved] Any built-in function in pandas/python which converts a list like data into a list

Yes, there is the split function, however before calling it on your string, you must get rid of the [ and ], or else instead of [‘1’, ‘2’, ‘3’, ‘4’], you will get [‘[1’, ‘2’, ‘3’, ‘4]’], so instead of s.split(), we do s[1:-1].split(), also this means your list is strings instead of ints (‘1’ … Read more

[Solved] OCaml: How can I return the first element of a list and after that remove it from the list?

I think there are a couple of misunderstandings here. First, most types in OCaml are immutable. Unless you use mutable variables you can’t “remove it from the list”, you can only return a version of the list that doesn’t have that first item. If you want to return both things you can achieve that using … Read more

[Solved] Python sorting a list of pairs

Here is a method to do what you are trying to achieve. unsorted = [[1, 0], [2, 0], [3, 0], [4, 2], [5, 2], [6, 5], [7, 6], [8,0]] sortList = [] sortDict = {} for x in unsorted: if x[1] != 0: if x[1] in sortDict: sortDict[x[1]].append(x[0]) else: sortDict[x[1]] = [x[0]] for x in … Read more

[Solved] how to convert string consisted of list to real list [closed]

You can use ast.literal_eval to safely evaluate strings containing Python literals. from ast import literal_eval a=”[“Hello”, “World!”, 2]” b = literal_eval(a) # [“Hello”, “World!”, 2] Note that the string can only be compromised of: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None (taken from the documentation here) solved how to convert string consisted … Read more

[Solved] How to resolve ClassCastException: java.lang.String cannot be cast exception

You are trying to change List<String> to List<tcmb> and problem lies here public static List<tcmb> getList(Activity a){ // your code // List<String> itemList = new ArrayList<String>(); itemList.addAll(Arrays.asList(itemWords)); dovizList = (List)itemsList; Log.d(TAG, “getValuestcmb: ” + dovizList.size()); return dovizList; Also, I don’t understand, what exactly you are trying to achieve here. List<String> itemsList = new ArrayList<String>(); dovizList … Read more

[Solved] Python 3.6: when a value in a list changes, find the sum of the values in another list?

Now that I understand that the list A itself is not going to change, but you expressed the idea of change meaning that the list has partitions where there are adjacent elements that are different, then a different solution comes to mind: Given your original data: A = [‘1′,’1′,’1′,’3′,’3′,’4’] B = [‘5′,’9′,’3′,’4′,’8′,’1’] We can use … Read more