[Solved] Iterate over list

[ad_1] You need to break up the rows and convert each value to an integer. At the moment you are looking for the presence of the string “3” which is why strings like “2;13” pass the test. Try something like this: list_6 = [“4;99”, “3;4;8;9;14;18”, “2;3;8;12;18”, “2;3;11;18”, “2;3;8;18”, “2;3;4;5;6;7;8;9;11;12;15;16;17;18”, “2;3;4;8;9;10;11;13;18”, “1;3;4;5;6;7;13;16;17”, “2;3;4;5;6;7;8;9;11;12;14;15;18”, “3;11;18”, “2;3;5;8;9;11;12;13;15;16;17;18”, “2;5;11;18”, … Read more

[Solved] Create list from user input and modify some elements

[ad_1] If you dont want to use list comprehension: my_list=[] for i in range(5): n=int(input(“Enter and integer number:”)) my_list.append(n) print(my_list) for index, i in enumerate(my_list): if i%5==0: my_list[index] = i + 5 print (my_list) 1 [ad_2] solved Create list from user input and modify some elements

[Solved] Remove quotes from list items without making it a string

[ad_1] You may use below list comprehension using map with eval(…) as: import ast Users = [‘Protein(“SAHDSJDSFJH”), {“id”: “s1”}’, ‘Protein(“ACGTWZJSFNM”), {“id”: “s2”}’, ‘Protein(“ABHZZEQTAAB”), {“id”: “s3”}’] new_list = [y for x in map(eval, Users) for y in x] where new_list will hold the value: [Protein(“SAHDSJDSFJH”), {‘id’: ‘s1’}, Protein(“ACGTWZJSFNM”), {‘id’: ‘s2’}, Protein(“ABHZZEQTAAB”), {‘id’: ‘s3’}] PS: Note that … Read more

[Solved] Syntax error on token “.”, @ expected after this token [duplicate]

[ad_1] When you do Type[] arr = { …, … }; that’s an array initializer. It can only be used in array declarations (or in array creation expressions, i.e. new String[]{“a”, “b”}). Arrays.asList is defined to take varargs arguments (asList(T… a)), so you do not have to wrap your arguments in an array first: Arrays.asList(“text”, … Read more

[Solved] how to modify the output [closed]

[ad_1] 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] … Read more

[Solved] How to change this list tuple into list only in Python? [closed]

[ad_1] test = [[(u’hello’,), (u’hello’,)], [(u’hello’,)]] for i, part_i in enumerate(test): for j, part_j in enumerate(part_i): test[i][j] = str(part_j[0]) Or, if you prefer the one-line version: test = [[(u’hello’,), (u’hello’,)], [(u’hello’,)]] result = [[str(j[0]) for j in i] for i in test] [ad_2] solved How to change this list tuple into list only in Python? … Read more

[Solved] Why is it giving me the error “method ArrayList.add(String) is not applicable”?

[ad_1] Problem: ArrayList<String> means you want an array-backed list that can hold String objects. This restricts the add method to only accept strings. The mistake you are making is that you are passing other non-String objects into the add method. Bad Answer 1: The easy way out is to change it to ArrayList<Object>, but this … Read more

[Solved] how to remove [ , ] and single quote in class list in python 3 in single line of code? [closed]

[ad_1] Based on your update on what bid_data contains: Do: int(bid_data[6].split(‘:’)[1].strip()) # returns an integer Explanation: The Python string method strip() removes excess whitespace from both ends of a string (without arguments) Original below: Below is based on using the input you gave, [‘Quantity Required’, ‘ 1’], to get the output of 1 If the … Read more

[Solved] How to merge list of dictionaries in python in shortest and fastest way possible?

[ad_1] One of the shortest way would be to prepare a list/set of all the keys from all the dictionaries and call that key on all the dictionary in the list. list_of_dict = [{‘a’: 1, ‘b’: 2, ‘c’: 3}, {‘a’: 3, ‘b’: 5}, {‘k’: 5, ‘j’: 5}, {‘a’: 3, ‘k’: 5, ‘d’: 4}, {‘a’: 3}] … Read more