Questions tagged [list]

44710 questions
1

votes
1

answer
3.1k

Views

Error illegal start of simple expression

I am having this error : error: illegal start of simple expression def process_alcs(lines: List[String]) : List[(String, Double)] = for (line
Ruben Lejzerowicz
1

votes
1

answer
389

Views

Behaviour of “containsAll” with duplicates

The official documentation (archive) of containsAll only says 'Returns true if this list contains all of the elements of the specified collection.'. However, I just tested this: List list1 = new ArrayList(); list1.add(1); list1.add(2); list1.add(1); List list2 = new ArrayList(); list2.add(2); list2....
Fabian Röling
1

votes
2

answer
134

Views

less common words in a python list [closed]

I have done the counter of most common words to keep only the 128 most common words in my list in order: words = my_list mcommon_words = [word for word, word_count in Counter(words).most_common(128)] my_list = [x for x in my_list if x in mcommon_words] my_list = OrderedDict.fromkeys(my_list) my_list...
Eduardo Andrade
-2

votes
1

answer
20

Views

How to code add method in double linked list using interface?

I have to code the add method in List using interface. i tried but its not even working. can anyone help me. interface and list class are given below: /** * Inserts the specified element at the specified position in this list. * Shifts the element currently at that position (if any) and any subseq...
jhalock bhandari
1

votes
1

answer
49

Views

Can one count the matches of multiple strings in one list?

I do not want to count the occurrence of one item but multiple items. The variable match contains a list of strings. I want to search the target list how many of the match items are in the target list. match = ['Manager', 'Access Responsible'] My dictionary contains the following entries: dict = {'W...
Alex_P
-1

votes
1

answer
16

Views

Why does indexing into a list with list[n] instead of list[[n]] in R not do what you would expect?

In an R list, why does indexing with [n] instead of [[n]] not return the nth element as non-R-programmers would expect? lfile
smci
0

votes
1

answer
19

Views

why the swapping does not take place when indices are 0 and 1?

I have an unordered array consisting of consecutive integers [1, 2, 3, ..., n] without any duplicates. It is allowed to swap any two elements. I need to find the minimum number of swaps required to sort the array in ascending order. Starting from the first element of the list, I try to put them in...
Golluu
1

votes
2

answer
45

Views

Splitting list to many lists with conditions

I am having such code to make 4 lists from one with my conditions. It is splitting depends on sign of elements of lists. Like I want to get list with all positive,list with lists where first elements are positive and second are negative ,etc...And all combination like this. It is easy to create 4 li...
1

votes
1

answer
39

Views

C-Linked-List: How do I save the 'Head' in a 'Temp' var so I don't have to traverse backwards each time

If I traverse my linked list for any reason, print, sort, etc... I have to re traverse it backwards to reset the head. Is there a better way to do this? struct list_node { struct list_node *next; struct list_node *prev; char word[30]; int word_count; }; typedef struct list_node list_node; struct li...
seamus
1

votes
2

answer
45

Views

Converting Map<key, value> to List<value>

I've been searching for a while without success. I am trying to convert a Map to a List (discarding key). Sure, I can do var addictionList = new List(); dataMan.forEach((String date, AddictionDay day) { addictionList.add(day); }); but is there a more straight approach, like var addictionList = dat...
Martin.
1

votes
4

answer
37

Views

Check if a list of byte arrays contains a new byte array

I have a list of byte arrays and need to check if this list doesn't contain a new given byte array. If not, than I need to perform some action. Right now, I'm trying to do it like this: List listOFByteArrays = getListOfByteArrays(); byte[] newByteArray = getNewByteArray(); if (!listOfByteArrays.cont...
Coffemanz
1

votes
1

answer
29

Views

Python + operator used with list type [duplicate]

This question already has an answer here: Different behaviour for list.__iadd__ and list.__add__ 2 answers Let's say my list a is [1,2,3] which points to address 53367992 >>> a = [1,2,3] >>> id(a) 53367992 Now, when I add [9] to this list, I understand the change of address, now l points to 5336855...
sans0909
1

votes
3

answer
35

Views

How to find average, maximum, and minimum numbers of a list from user input in HTML

I'm trying to make a code that will evaluate numbers in a list from user input and will calculate the sum, average, minimum, and maximum of that list. I have already gotten the sum part from help from others. I can't seem to find how to get the maximum and minimum numbers from the list. Im trying to...
Max Muchnick
1

votes
1

answer
37

Views

How to search index of an object having a certain property in list?

Assuming i have a list of objects and objects has a property named as key. how can i search for index of the object which has a key of 1.
wasif
1

votes
1

answer
45

Views

I have a all the rows with a particular column with lists. Select rows that does not contain atleast one element from the target list

I have a data frame which has rows that contain lists (Lets call B) I have a target list (let's call A). I want to store all the rows, that does not have at least one common element in B and A. A = [ 'IAB24', 'IAB9-WS1', 'IAB9-WS2', 'IAB26-WS1', 'IAB9-9', 'IAB14-WS1', 'IAB14-1', 'IAB19-15', 'IAB25-5...
Srini
1

votes
2

answer
50

Views

Create a list of dictionaries with unique keys from a list of dictionaries with duplicated keys

I have a list of dictionaries: records = [{id:123, name:'Course A', enrolled_date:'1st Feb'}, {id:123, name:'Course A', enrolled_date:'1st Jan'}, {id:456, name:'Course B', enrolled_date:'1st Jan'}] I want to create a new list of dictionaries from this data. The new list should only contain diction...
Zak Smith-Sanga
1

votes
2

answer
72

Views

Haskell Nested List Comprehensions

I am studying for an exam and I am looking at an example of nested list comprehensions from the book 'Learn you a Haskell', and I was hoping if anyone could explain me step by step how to analyze it and come out with its output. let xxs = [[1,2,3],[2,3,4],[4,5]] [ [ x | x
wwww
1

votes
4

answer
60

Views

How to create a dictionary to reverse lookup list items that each have sets?

I have test names in a list like this in Python v2.7: all_tests = ['test1', 'test2', 'test3', ..., 'testN'] And for each test name, I can lookup a set of properties that the test has: series['test'] = {'prop1', 'prop2', 'prop3', ..., 'propN'} E.g., series['test1'] = {'yellow', 'blue', 'orange'} seri...
WilliamKF
1

votes
4

answer
35

Views

Python Print list on separate lines

I'm trying to print my leader board out however its printing it on one line instead of multiple. So far this is my code: cursor.execute('SELECT username, score FROM Players order by score DESC limit 5') topscore = cursor.fetchall() topscore = list(topscore) print(topscore) And when it runs it output...
Jack Vincent
1

votes
1

answer
32

Views

Convert dataframe into list

I would like to convert a dataframe containing zip codes and relationships between zip codes into a list. I looked at ways to convert dataframes into lists as well as the spread function. The first column (codes1) contains all zip codes of a zone. The second column (codes2) contains the zip codes...
helene
1

votes
2

answer
54

Views

why do the assignment statement in cycle only executes once in python

I think it is different from C language habits in mine. I want to excute assignment statement every times, so how to do it? input a = [0,1,2,3,4,5] for i in range(6): b = a print(len(b)) c = b.pop(i) output 6 5 4 3 Exception has occurred: IndexError pop index out of range It seems like b = a only ex...
Zhengfang Xin
1

votes
1

answer
35

Views

R iterate through list of dataframes to create new column

I have a list of dataframes DFList. For every dataframe in DFList i would like to create a new column X4. Small Example X1
Paul
1

votes
3

answer
58

Views

Select element in list of values in dictionary

I have a dictionary with the values being list with 2 or more elements. I want to slice in those values with more than 2 elements based on the other values with only 2 elements in their list. I know i can append all the value elements to a list and then just count the most common, but i need to kee...
RAHenriksen
1

votes
2

answer
10

Views

capitalize next non-empty element in next list of nested lists

My function aims to take a string as input then output the same string printed the number of times equal to the count of non-empty characters in the string, with the next non-empty element in the next list capitalized. The final output should contain the new strings in a list. Example: Input: hell...
Mr. Jibz
1

votes
3

answer
27

Views

Python append to return dict instead of a list

The append below is working but it is return a list instead of a dict. So when I tried the extract the key/value with tag.items() it is telling me that there's a ValueError: not enough values to unpack (expect 2, got 1) This is the correct error message as it a list as all_tags.append creates a lis...
munchine
1

votes
2

answer
29

Views

How to remove empty tibbles from a list of tibbles returned by get_friends function?

I am using the get_friends function of rtweet package to get the list of user_id's of the friends of a set of focal users who are sampled from participants in a Twitter discourse. The function returns a list of tibbles. Each tibble has two columns - one with the focal user's user_id and the second...
Sunil Reddy
1

votes
2

answer
46

Views

Removing specific element from a list of vectors in R

Suppose I have a list of indices and values. indx_list
stats134711
1

votes
3

answer
93

Views

How to sort lists of objects using java

I have 2 lists which are holding the same objects but unordered and I want to sort them first before comparing them in order to check whether they are equals. One item of each list looks like that: first list: AuditRow{dateStr='2019-04-15 11:16', userStr='admin', entityStr='Users'} second list: Aud...
tupac shakur
1

votes
2

answer
43

Views

How to remove last item of a list/array no matter the length

I am trying to remove the last item of a list/array even if there are duplicate items EG list = ['h','e','l','l','o',' ','t','h','e','r,'e'] It would remove the final 'e' but not the second and ninth 'e' I have already tried finalSentence.remove([finalSentence[len(finalSentence)-1]]) However this r...
Jeff Kint
1

votes
2

answer
31

Views

Conditional merging of sublists in a list

I have the following list of lists. If last sublist has len>1: x = [[0], [1, 2, 3], [4, 5], [6], [7, 8, 9], [10, 11, 12, 13], [15], [16, 17, 18]] expected_output = [[0, 1, 2, 3], [4, 5], [6, 7, 8, 9], [10, 11, 12, 13], [15, 16, 17, 18]] If last sublist has len==1: x = [[0], [1, 2, 3], [4, 5], [6], [...
1

votes
2

answer
138

Views

how to group near points in list in python

I am getting a list using a list comprehension. lat say I am getting this list using this line of code bellow: quality, angle, distance = measurements[i] new_data = [each_value for each_value in measurements[i:i + 20] if angle
Kazi
1

votes
3

answer
72

Views

How to fix this unchecked cast error when using generics?

In my class I have a list containing TopicNodes. The nodes of those list should extend from the Message class. In the method findNode within the list of nodes there is searched for a node with a specific topic and if it matches it is being returned. The Java compiler complains about the TopicNode be...
Klyner
1

votes
2

answer
28

Views

How to grep strings that matches two (or more) variables in R

I have a list from which I would like to extract specific elements to put into a new list e.g. MyFullList = ( ' 'BLUEh473vs65hRED7vfd8edgf9GLOSS.csv', 'BLUE5654vsy56hgfREDjkgr7MATTE.csv', 'BLUEhjirhgccsREDgfigjINCAN.csv', 'BLUEvfdjhkldfgsGREENdfggh5GLOSS.csv', 'BLUEtgergvsGREENsghjkhgnMATTE.csv'...
Solebay Sharp
1

votes
1

answer
23

Views

Sort dtypes by alphabetical order

Imagine that we had a mock pandas data frame like this: x = [1, 1000, 1001] y = [200, 300, 400] cat = ['first', 'second', 'third'] df = pd.DataFrame(dict(speed = x, price = y, award = cat)) The data frame df would look like this: speed price award 0 1 200 first 1 1000 300 se...
NuValue
1

votes
1

answer
40

Views

How could we access the multiple dict in a list?

I have a list which contains multiple dict and all the dict have same key but different values. I want to get a dict which has maximum value for a particular key. l = [{'a':23, 'b': 64, 'c':4},{'a':83, 'b': 34, 'c':47}] I want to get a dict which has maximum value for 'b'.
Kumar Mayank
1

votes
2

answer
37

Views

Linked list with memory leak issues

This program is acting as a template for what will be a linked list of bunny objects with unique names and colors. int Nodes::insert() { Node* new_node = (Node*) malloc(sizeof(Node)); new_node->name = getName(); new_node->prev = NULL; new_node->next = head; if (head != NULL) { head->prev = new_node...
MChess404
1

votes
2

answer
25

Views

unlisting a list while keeping the indices

I have a list which can have either empty entries, entries containing one elements and entries containing multiple elements. l1 = list(integer(0), 11L, integer(0), integer(0), 11L, 11L, c(6L, 36L), 16L, 16L, integer(0), integer(0)) I would like to unlist l1 and create a data frame, where for the e...
Omry Atia
1

votes
3

answer
32

Views

How can i find max element index for a specific value in list composed of class objects?

I want to find a maximum elements index in a nested list for each row. I got this error: maxe = array[i].index(max(e_object.x for e_object in array[i])) ValueError: 5 is not in list class e_object(): def __init__(self,x): self.x = x array = [] array.append( []) array[0].append(e_object(0)) array[0]....
Şevval Kahraman
1

votes
3

answer
41

Views

Using list comprehension with over 4 conditions

I have a list of lists. Each sub-list contains two integer elements. I would like to multiply each of these elements by 1.2 and if they are positive and bigger then a certain number, change them to be that certain number. same thing if they are smaller. The multiplication bit I achieved using list c...
Omri. B
1

votes
3

answer
27

Views

Comparison of list to list of lists and return the other element from the list of list

I have a list - answers: [0,1] and another list of list - questions: [[0,ABC], [1,DEF], [3,XYZ]] How can I compare the 2 and return ABC, DEF based on the comparison of all elements in answers to first elements in the list of list?
Dhruv

View additional questions