FAQ Database Discussion Community


Filter list using Boolean array

python,list
How can I use boolean array as index to filter a list? For example: >>> l = ['a','b','c'] >>> b = [True,False,False] >>> l[b] The result should be: ['a'] I know numpy support it but want to know how to solve in Python. >>> import numpy as np >>> l...

Storing list element address into dictionary

python,list,dictionary
I have 2 data structures - list, and dictionary. List holds a bunch of keys. Dictionary has those same keys. As for the value of each key, I want to store the address of corresponding element in the list. What would this achieve: For a key, I would lookup the...

Python RuntimeError: maximum recursion depth exceeded in cmp

python,list,dictionary,recursion
I have a complex data structure that I'm trying to process. Explanation of the data structure: I have a dictionary of classes. The key is a name. The value is a class reference. The class contains two lists of dictionaries. Here's a simple example of my data structure: import scipy.stats...

Datastructure choice issue

python,list,python-2.7,data-structures,tuples
I'm new to python. I need a datastructure to contain a tuple of two elements: date and file path. I need to be able to change their values from time to time, hence I'm not sure a tuple is a good idea as it is immutable, and every time I...

Creating a list of items with different tags + filter

javascript,html,list,filter
I have prepared an example what I would like to produce: link. I have already looked for something and I have found the way to create a filter but just for one value... In my case I need more values all together combined. So that if I wanted a flat...

Finding the longest list in a list of lists in Python

python,list
I have to fing the longest list of lists in Python. For example: longest([1,2,3]) returns 3 longest([[[1,2,3]]]) also returns 3 (inner list is 3) longest([[], [3,[4,5],[2,3,4,5,3,3], [7], 5, [1,2,3], [3,4]], [1,2,3,4,5]]) returns 7 (list [3,[4,5],[2,3,4,5,3,3], [7], 5, [1,2,3], [3,4]] contains 7 elements) Right now I have this code, but it...

I need to make sure that only certain characters are in a list?

python,regex,string,list,python-2.7
I have this to get input and put it in a list: def start(): move_order=[raw_input("Enter your moves: ").split()] And I only want the characters A, D, S, C, H (it's for a game >_>) to be allowed. I've tried using the regular expressions stuff: if re.match('[ADSCH]+', [move_order]) is False: print...

Pandas Series of lists to one series

python,string,list,pandas,series
I have a Pandas Series of lists of strings: 0 [slim, waist, man] 1 [slim, waistline] 2 [santa] As you can see, the lists vary by length. I want an efficient way to collapse this into one series 0 slim 1 waist 2 man 3 slim 4 waistline 5 santa...

Multiple NULL addition into a List in Java

java,list,concurrency,null,add
I have 2 lists and want to copy some element from one to another, i.e. there are old and new employees list I need to union 2 lists and delete the elements that include to the old list but not include in the new one. I could solve the part...

Merge 2 lists of lists, element by element [duplicate]

python,list
This question already has an answer here: How to zip two lists of lists in Python? 5 answers I've 2 lists of list, for example: a = [['a','b','c'],[1,2,3]] b = [['d','e','f'],[4,5,6]] What I need is: c = [['a','b','c','d','e','f'],[1,2,3,4,5,6]] I can't figure out how to do this, any help is...

Find a single duplicate in a list of lists Netlogo

list,duplicates,netlogo
I am trying to find a duplicate between the sublists of a list , if I have this list let listA [[-9 2] [-9 1] [-9 0][-9 -1][-9 -2][-9 -3][-9 -4][-8 0][-9 0]] and it is a restriction that this list can have only one sublist that can be repeated...

Reduction of list dimensions in Python

python,list,indexing,nodes
I'm trying to assign classes to a list of nodes, and separate all nodes into separate lists based on class tag. For example, if we have the following code: #define number of classes MaxC=5 index=[4 4 5 1 4 1 4 5 4 4 3 1 3 3 1 1]...

How to display list items as columns preserving the left-to-right order?

css,list,multiple-columns,flexbox
Is it possible in pure CSS to lay out list elements to arbitrary number of columns, preserving the left-to-right order, as on this example? ...

How to add empty value from gridview cell to list?

c#,linq,list,datagridview,datagridviewtextboxcell
I want to enter guest details(Title,Firstname,midname lastname) in a list<string> ,the guest details can be empty.I'm using LINQ for inserting in the list.I had referred this question for the LINQ code DataGridView write all values from a column to list All I want to do is enter the text into...

Writing PHP variable based on jQuery calculations and displaying predetermined value

php,jquery,list,variables,automation
Context: I'm trying to make an automatically generated list that has a different amount of items on each page. Each item needs a name and a link, based on its place on the list. Here's an example with two items for the problematic part: PHP variables: $item_link_1 = "link1"; $item_name_1...

Operand order in Scala List.prepend (::)

list,scala,operators
Odersky has brilliantly optimized Java syntax, enabling object calls without dots and parenthesis. I.e. instead of list.prepend(item), you now simply write list :: item, which also turns language operators into simple object methods. Here, List defines :: (prepend) operator. However, you normally write it vice-verse in Scala, using item ::...

Iterate over 'complex attributes' json object on Angular

javascript,json,angularjs,list
I have a list of items that I take from a json file via one service. At the end of the list a button can let you add every item to a list containing the elements that you have clicked/add. You can add same item only when you don't exceed...

join two different list by id into one list

c#,list,join,merge,automapper
I've got two different list of two different objects. Then i got one list of a viewmodel that contains properties from both the objects and i want them to be joined into that list. //Product public string id { get; set; } public string unitMeasurement { get; set; } public...

References to mutables (e.g., lists) as values in Python dictionaries - what is best practice?

python,list,dictionary
It is possible to map a dictionary key to a value that is a reference to a mutable object, such as a list. Such a list object can be changed by invoking a list method on the reference, and the changes will be reflected in the dictionary. This is discussed...

represent an index inside a list as x,y in python

python,list,numpy,multidimensional-array
I have a list which contains 1000 integers. The 1000 integers represent 20X50 elements of dimensional array which I read from a file into the list. I need to walk through the list with an indicator in order to find close elements to each other. I want that my indicator...

Convert List to typeof UnderlyingSystemType

c#,list,inheritance,reflection,dynamic-linq
I am currently working on code that is using dynamic-linq, I ran into a problem when using a List<BaseClass>, where the list actually contains a list of the Person Class. When I execute the following code I get a ParseException: var list = new List<BaseClass>(); list.Add(new Person { FirstName =...

Is there a way of avoiding so many list(chain(*list_of_list))?

python,list,nested-lists,itertools,chain
If I have a list of list of list of tuples of two strings. I want to flatten it out to a non-nested list of tuples, I could do this: >>> from itertools import chain >>> lst_of_lst_of_lst_of_tuples = [ [[('ab', 'cd'), ('ef', 'gh')], [('ij', 'kl'), ('mn', 'op')]], [[('qr', 'st'), ('uv',...

C# 2D Generic List [closed]

c#,list,nested-lists
I'm working on a talents/skills tree system for my game made with Unity and I've got a class for my 45 talents buttons that looks like this: public class SaveTalentClass { public int talId; public int talCurRank; public int talMaxRank; public SaveTalentClass(int id, int cRank, int mRank) { talId =...

Collapse list of lists to eliminate redundancy

python,list
I have a couple of long lists of lists of related objects that I'd like to group to reduce redundancy. Pseudocode: >>>list_of_lists = [[1,2,3],[3,4],[5,6,7],[1,8,9,10]...] >>>remove_redundancy(list_of_lists) [[1,2,3,4,8,9,10],[5,6,7]...] So lists that contain the same elements would be collapsed into single lists. Collapsing them is easy, once I find lists to combine I...

chunk of data into fixed lengths chunks and then add a space and again add them all as a string

regex,list,join,ironpython,findall
I have got hex values as a85b080040010000. I want it to be as a8 5b 08 00 40 01 00 00. I have done it by using below code. But I have to work with very large data. So I want computed time to be very low. import binascii import...

Sort List of Numbers according to Custom Number Sequence

list,python-2.7,sorting
Question :A set of numbers will be passed as input. Also the redefined relationship of the digits 0-9 in ascending order will be passed as input. Based on the redefined relationship, the set of numbers must be listed in ascending order. Input Format: The first line will contain the the...

Python - Using a created list as a parameter

python,list,loops,if-statement,compare
When I run my code it tells me: Type Error: unorderable types: str() < float(). I can't figure out why it won't let me compare these two numbers. The list I am using is defined, and the numbers in it have been redefined as floats, so I'm not sure what...

Zip with tuples and list

python,string,list,zip,tuples
I need to write a code that will return the characters of two strings as a list of tuples. The code should stop when either one of the strings runs out of characters. I know is a simple code but I cannot get to work where it gives me more...

Python Convert set to list, keep getting TypeError: 'list' object is not callable

python,list,set
I am trying to write a program that adds items to a list based on a random number. Part of the program is potentially rolling additional items, but all duplicate items should be rerolled. My issue is that when I try to do this using the methods I was able...

ZipList with Scalaz

list,scala,scalaz,applicative
Suppose I have a list of numbers and list of functions to apply to numbers: val xs: List[Int] = List(1, 2, 3) val fs: List[Int => Int] = List(f1, f2, f3) Now I would like to use an Applicative to apply f1 to 1, f2 to 2, etc. val ys:...

Easiest way to Add lines wrong a .txt file to a list

c#,string,list,streamreader
At the moment I am opening the .txt file twice, once to get the number of all the lines, second to add a line to a list as much as how much lines there are in the .txt file. Is there an easier/better way to do this? This is my...

Intersection of two lists using LINQ

c#,database,linq,list,intersect
I have a User called admin who has a list of Companys. I want to return a list of Users who have one or more of the same Companys. I am using Linq using this query but I'm not sure why it is not working. I don't really understand what...

Why cant I refer to a random index in my 4D list, while I know it exists?

c#,list,for-loop,dimensions
I got a 4D list, and I want where I want to display only the [k][3][j][z], but this isnt working. I checked all the counts and they are all 5+, so 3[4] should work... for (int k = 0; k < lijst4D.Count; k++) { for (int i = 0; i...

Python appending a list to a list and then clearing it

python,list
I have this part of code isolated for testing purposes and this question noTasks = int(input()) noOutput = int(input()) outputClist = [] outputCList = [] for i in range(0, noTasks): for w in range(0, noOutput): outputChecked = str(input()) outputClist.append(outputChecked) outputCList.append(outputClist) outputClist[:] = [] print(outputCList) I have this code here, and...

How to call a list for update multiple times until a condition is fulfilled in Netlogo

list,procedure,netlogo
I am new to Netlogo and still learning , what i want to do is call a list after an update is done and do another update to it until a condition is reached , if a have a list let xy [[-2 6][-1 6][0 6][-1 6][-2 6][1 5][2 5][-3...

make all elements in list equal with minimal cost

list,optimization,prolog
I am trying to create a prolog program that allows to convert a list into a list with the same length consisting of only 1 element from the original list. This element must be chosen in such a way that a minimal number of elements from the original list needs...

Re-order li elements with JavaScript

javascript,html,css,list
I have an li which shows location in an alphabetical order and I'd like to grab the elements of the list and return with a different order. <li class="single-contact-location"> <span>Location</span> ALocation, BLocation, CLocation, DLocation, ELocation, FLocation </li> Let's say BLocation, ALocation, CLocation, DLocation, ELocation, FLocation With var li = document.getElementsByClassName("single-contact-location")[0];...

How create many list as array?

c#,arrays,string,list
I have a problem on creating a set of list in array this is my coding but it's wrong one, any correction for this? List<string>[] item = new List<string>[10](); I want to create 10 list in string named as item but I can't do it and then how can I...

Use poll() on new subprocess.Popen object list

python,list,popen
I'm trying to write some code that polls a list of subprocess.Popen objects (?) created as such: self.processList = [subprocess.Popen for i in range(8)] My code will be creating new subprocess.Popen objects and assigning them to different locations in the list. I can then successfully use poll(). But before any...

Sorting a list with dictionaries, django

python,django,list,sorting,dictionary
myFrom two models in django i have created a list of dictionarys where each dictonary is a row in a table I show in the client. I would like to be able to sort this list for each of the different "columns". objdict = [] mydict = { 'thing1': model1.val1,...

Insertion into a list doesn't reflect outside function whereas deletion does?

list,lisp,common-lisp
I am new to Lisp. Deletion of an item in a list by a function gets reflected outside the function but insertion doesn't. How can I do the same for insertion? For example (defun test (a b) (delete 1 a) (delete 5 b) (append '(5) b) (member '5 b)) (setq...

Loop by Object inside another Object in Java

java,list,oop,collections
I'm not sure how to ask this in word so here's an example : Building class have a data like this : Map<Season, List<Info>> infosBySeason = new TreeMap<Season, List<Info>>(); What I'd like to do is loop for each Building, print by Season infos. Like : Season 1 : Building 1...

Idiomatic list construction

list,haskell,functional-programming,idiomatic
I'm very new to Haskell and functional programming in general, so I don't really know how to make this code idiomatic: type Coord = Double data Point = Point Coord Coord Coord deriving Show type Polyline = [Point] -- Add a point to a polyline addPoint :: Polyline -> Point...

For-loop does not go over all objects

python,list,for-loop
Why does this for-loop not go through all items: temp = 0 for br in my_list : temp +=1 #other code here #my list is not used at all, only br is used inside here my_list.remove(br) print temp assert len(my_list) == 0 , "list should be empty" So, assertion fires....

How to get a reference of the list inside the list comprehension in Python

python,list
In previous Python versions, it was possible to get a reference of the list inside the list comprehension by calling locals()['_[1]']. As it seems not to work anymore, is there another way to get it? For example, in the following code, I would like to use the result of the...

List of type T to Dictionary

c#,list,dictionary
I have an object List<T> and a keyfieldName of Type T i am trying to convert this List<T> to an Dictionary<string,double> for example if Type T is of type Person, i will be given keyfieldName ="UserId" ListItem1==> Person UserId 1 Firstname : "John" Lastname "Doe" ListItem2==> Person UserId 2 Firstname...

C++ atomic list container

c++,list,stl,containers,atomic
Probably this is a stupid question and I get downvoted but I'll ask it anyways. I'm playing around with std::atomic but I think I didn't fully understand the concept. I'm wondering why there are no atomic Containers. So I played a Little bit around. First I tried the following: std::atomic<std::list<int>...

Python 3.4: List to Dictionary

python,list,python-3.x,dictionary
I have a string as follows : ['Total Revenue', 31821000, 30871000, 29904000, 'Cost of Revenue', 16447000, 16106000, 15685000, 'Gross Profit', 15374000, 14765000, 14219000, 'Research Development', 1770000, 1715000, 1634000, 'Selling General and Administrative', 6469000, 6384000, 6102000, 'Non Recurring', '-', '-', '-', 'Others', '-', '-', '-', 'Total Operating Expenses', '-', '-', '-',...

Sort when values are None or empty strings python

python,list,sorting,null
I have a list with dictionaries in which I sort them on different values. I'm doing it with these lines of code: def orderBy(self, col, dir, objlist): if dir == 'asc': sorted_objects = sorted(objlist, key=lambda k: k[col]) else: sorted_objects = sorted(objlist, key=lambda k: k[col], reverse=True) return sorted_objects Now the problem...

Python 2.7 “list index out of range”

python,list
I keep getting "IndexError: list index out of range", the code does fine with things like "s = 'miruxsexxzlbveznyaidekl'" but this particular length makes it throw an error. Can anyone help me understand what I did wrong here, not just give me the answer? (I'd like to not have to...

JSON parse will not execute with JavaScript

javascript,json,list,parsing
This is my current code, any help would be greatly appreciated. I need to call my listApp.json file and parse it. I want to display my list which currently has one link. I'm new to this. <script type = "text/javascript"> // If the .js files are linked correctly, we should...

Flatten out a list in java

java,algorithm,list
I was asked this question in an interview Given a hypothetical list in java that, along with holding integer content, may also hold another list of similar type Example: [1,3,5,[6,7],8,9,10,[11,13,15,[16,17,[18,19]]],20] Output should be: [1,3,5,6,7,8,9,10,11,13,15,16,17,18,19,20] Easy I thought! So i came with a recursive solution that solved the problem! Or not?...

Get a list of N items with K selections for each element?

python,list,list-comprehension
For example if I have a selection set K K = ['a','b','c'] and a length N N = 4 I want to return all possible: ['a','a','a','a'] ['a','a','a','b'] ['a','a','a','c'] ['a','a','b','a'] ... ['c','c','c','c'] I can do it with recursion but it is not interesting. Is there a more Pythonic way?...

Saving elements of a list as data.frames using R

r,list,save,lapply
How can I save each element of a list in a in a separate .RData file? Consider the following example: # Generating a list containing 3 matrices set.seed(1) mylist=list(M1=matrix(LETTERS[sample(1:26,9)],3),M2=matrix(LETTERS[sample(1:26,9)],3),M3=matrix(LETTERS[sample(1:26,9)],3)) mylist[1:2] # $M1 # [,1] [,2] [,3] # [1,] "G" "U" "W" # [2,] "J" "E" "M" # [3,] "N" "S"...

How to find the difference between two lists of dictionaries checking the key-value pair

python,list,csv,dictionary
I've already searched for a solution to my problem but with no success. Part of the solution for my problem is here, but this does not solve it all. I have two lists of dictionaries like this - each dictionary is written to a csv file but I read the...

print method for list changes values of items

python,list
I have problem with printing list. random_itemst_stac contains list of items (cards). Prints of elements and indexes in for loop works perfect but when I print a whole array there are X set for others items - it's strange. Card class: class Card(object): def __init__(self, r=0): self.__rank=0 self.__hidden= False if...

how to insert into python nested list

python,list,list-comprehension
I want to insert an item into a list inside a list. I'm wondering if someone can show me. list5 = [[], [(1,2,3,4), 2, 5]] print("1. list5", list5) list5.insert(0, (2,5,6,8)) print("2. list5", list5) Output: 1. list5 [[], [(1, 2, 3, 4), 2, 5]] 2. list5 [(2, 5, 6, 8), [],...

Grouping 0s and 1s in python

python,list,grouping
I have an array of zeros and ones like [0,0,0,1,1,1,0,0,0,1,1]. How to write a program to save neighboring 0's and 1's in different arrays. E.g. [0,0,0,1,1,1,0,0,0,1,1] giving [0,0,0],[1,1,1],[0,0,0],[1,1]....

Reordering HTML list items with JS

javascript,html,list
I'm trying to move a list item in a standard unordered list but have no idea where to start. I can't access the HTML and only have a client JS file so guess I would have to do it through JS. The list looks like this: <nav id="main_navigation"> <ul class="level_1...

How to print words from a word list that have 5 letters or less Python 2.7?

python,list,python-2.7
I'm sorta new to python, which you can probably see by my crappy coding below. If you were to play this game, you would probably find that it's really hard, so to make it easier, I want to make it so it only gives the user 5 letter words or...

Can not figure out how to print second dimension in three dimension List

c#,list,for-loop,dimensions
I am making lists in three dimensions. If I run my code it shows the following strings: list5 + list3 + list1. Now this is in three dimensions, so each dimension adds a word. If you look to the code there will be displayed: 4*4*4 = 64 possiblities. Now I...

Multi dimensional python dictionary [duplicate]

python,list,dictionary
This question already has an answer here: Generating python dict keys on the fly [duplicate] 3 answers I want to create a multi dimensional dictionary in python so that I can access them using the following notation: test['SYSTEM']['home']['GET'] test['SYSTEM']['home']['POST'] What would be the easiest way to set these values,...

Iteratively adding new columns to a list of data frames

r,list,for-loop,data.frame
I am trying to write some code that iterates through a list of data frames, adding to each a new column that contains the same values as an older column but shifted by 1. The first value in this column will be NA. Below is my code: for(dataframe in 1:length(listOfDataFrames)){...

Java Get and then remove from a list

java,list,setter,getter,instances
In my code i have a list of instances of a class. And i want to get a attribute of 1 instance which is ArrayList. In this class i have implement getters and setters. So I call listofinstances.get(i).getArrayList().remove(0); in order to remove the 1st item of this list. Is this...

Python: TypeError: list indices must be integers, not list

python,list,loops,indices
I've got two lists of coordinates, they look like this: list_kp2_ok: [[1185.60009765625, 933.6000366210938], [1310.4000244140625, 828.0000610351562], [1067.0, 979.0], [1310.0, 828.0], [1423.2000732421875, 814.800048828125], [1306.0, 828.0], [3634.0, 605.0], [1308.0960693359375, 827.7120971679688], [1422.7200927734375, 815.0400390625], [1185.1199951171875, 933.1200561523438], [1186.56005859375, 923.0400390625], [1306.3681640625, 829.4401245117188], [1194.393798828125, 839.80810546875], [1187.1361083984375, 922.7520751953125],...

why java API prevents us to call add and remove together?

java,list,collections,listiterator
As per Java API- IllegalStateException - if neither next nor previous have been called, or remove or add have been called after the last call to next or previous remove()- Removes from the list the last element that was returned by next() or previous() (optional operation). This call can only...

prolog misunderstanding. Split list into two list with even and odd positions. where is my mistake?

list,split,prolog
I'm trying to split a list into two other list. List Even with the elemnts in even possition and a List Odd with the others. I've been looking over iinternet a solution, but all seem to me like chinese, i can not understand the process. So this is what i've...

How to use list comprehensions to make a dict having list of list as values

python,list,for-loop
I Have a list as following and I want to convert that as output shown below using List comprehensions. Any help is appreciated. a = [{'type': 'abc', 'values': 1}, {'type': 'abc', 'values': 2}, {'type': 'abc', 'values': 3}, {'type': 'xyz', 'values': 4}, {'type': 'xyz', 'values': 5}, {'type': 'pqr', 'values': 6}, {'type':...

How to check if an element from List A is not present in List B in Python?

python,list
If I have one element alone this is easy: >>> 3 not in [2, 3, 4] False >>> 3 not in [4, 5, 6] True But what if I have two lists and have to check if the elements in list A occur in list B? A=[1,2,3,4] B=[4,5,6,7] How do...

Adding data from a csv file to a List using a loop

c#,list,csv
I am new to developing and this is my first question, so please excuse any misunderstanding in my explanation. I am trying to import the data from a csv file into a list of objects I defined. My file has 2 columns and 5 rows: 1 for the date and...

What is the easiest way to select a list-item in a html list with jquery or javascript?

javascript,jquery,html,list,listeners
I am busy writing a javascript/jquery based version of the game Battleship. In my overview-screen I have a list of games. What I would like to do, is that every time when I select (click on) a list-item, the background-color of the list-item changes and the selected item is saved...

Splitting a Datatable based on Column value

c#,list,datatable
I have a datatable containing a Bool(bit) Column. a b ------ ------ 1 10 0 20 1 30 0 20 1 10 I wish to split this into 2 independently sortable datatables based on this value (column a) I've had a look and found an old question: Split a DataTable...

How can I create a PNG image file from a list of pixel values in Python?

python,image,list,file,python-imaging-library
I can generate a list of pixel values from an existing image file using a procedure like the following: from PIL import Image image = Image.open("test.png") pixels = list(image.getdata()) width, height = image.size pixels = [pixels[i * width:(i + 1) * width] for i in xrange(height)] How could I convert...

Implementing a dictionary function to calculate the average of a list

python,list,dictionary
As always, I've attempted this for awhile before I proceed to ask a question on here. I know there are several attempts at answering this, but none really worked for what I needed. Here are the instructions: Implement the following three functions (you should use an appropriate looping construct to...

Convert only floating point numbers to int in list python

python,list,list-comprehension
I am trying to turn any floating point number in the list 'codes' to an int. codes = [890.0,'JFR'] codes = [int(c) for c in codes] I am getting the error: ValueError: invalid literal for int() with base 10: 'JFR' What I want the list 'codes' to be is: [890,'JFR']...

Stopping list selection in Python 2.7

python,list,python-2.7
Imagine that I have an order list of tuples: s = [(0,-1), (1,0), (2,-1), (3,0), (4,0), (5,-1), (6,0), (7,-1)] Given a parameter X, I want to select all the tuples that have a first element equal or greater than X up to but not including the first tuple that has...

How do I read this list and parse it?

python,list
I'm using requests and the output I get from the sites API is a list, I've been stuck trying to parse it to get the data from it. I use r = requests.get(urlas, params=params) r.json() to get the data I want. Here is a snippet of the list [{'relation_type': None,...

Can I put StreamReaders in a list? Or any other way to read a lot of text files at once?

c#,list,text,streamreader
I have a lot of text files and want to read them all by once, how do I do this? This is my code till now: List<StreamReader> lijst = new List<StreamReader>(); using (StreamReader qwe = new StreamReader("C:\\123.txt")) using (StreamReader qwer = new StreamReader("C:\\1234.txt")) lijst.Add(qwe); lijst.Add(qwer); But I get an ObjectDisposedException(Cannot...

Python regular expression, matching the last word

python,regex,list
I've the following problem. I'm looking to find all words in a string that typically looks like so HelloWorldToYou Notice, each word is capitalized as a start followed by the next word and so on. I'm looking to create a list of words from it. So the final expected output...

How can I iterate through nested HTML lists without returning the “youngest” children?

javascript,jquery,html,list,loops
Fiddle: https://jsfiddle.net/zayjeLrk/12/ I want to iterate through an HTML nested list that is 3-layers deep. <ul> <li>animals <ul> <li>birds <ul> <li>crow</li> <li>parrot</li> </ul> </li> <li>reptiles</li> </ul> </li> <li>plants</li> <li>bugs</li> </ul> I want it to iterate through the list so that it returns the elements in this order (note, this isn't...

Prolog: Summing elements of two lists representing an integer(restrictions inside not regular sum!!)

list,prolog
I was solving a problem: A list is representing an integer say 12345 by L=[12,34,5] each element should be from 0 to 99.The exercise is to write a function (sum) that sums two lists and gives the equivalent list of their sum which is representing the sum of two integers....

How to use Split() method in Android

java,android,string,list,split
I have String like this. ex:- String myString = "A=myPage{a1,b1,c1};B=myPage{a2,b2,c2};C=myPage{a3,b3,c3};" I need to put each {_,_,_} part into List. like: If List<String> list = new ArrayList() then, list[0]="a1,b1,c1", list[1]="a2,b2,c2", list[2]="a3,b3,c3" I tried to use split, but I don't know how to apply it into this for getting my result. for...

Django: Handling several page parameters

python,django,list,parameters,httprequest
I have several possible parameter to process in a page. Assume x0, x1, x2,..., x1000. It seems awkward to get and process them one by one by request.GET.get('x0'), request.GET.get('x1'), ... Any idea to put them in a list, so that they can be processed in a loop....

Get and add all properties of type Mname from a list of objects and add them dynamically too a drop down

c#,linq,list,object,properties
Ok so I have an object type called monsters and a list of all monsters I need to get all the strings from the property called MName and add each one to a Drop down text box. here is the class so far.(sorry Im really new to coding.) using System;...

For each “sub item” in json array, get name, then the value for a sub item

python,arrays,json,list
I apologize for the poor title. I'll try to explain what I want to achieve as best as I can. Here is my (example) json: { "1": { "2": { "3": { "9": 10, "8": 11, "7": 12 }, "4": { "9": 13, "8": 14, "7": 15 }, "5": {...

group indices of list in list of lists

python,list
I am looking for an elegant solution for the following problem. I have a list of ints and I want to create a list of lists where the indices with the same value are grouped together in the order of the occurrences of said list. [2, 0, 1, 1, 3,...

deserialize a list of Guid c#

c#,list,serialization,guid
Can anyone help me to deserialize this xml file into a list of Guid ? <?xml version="1.0" encoding="UTF-8"?> <content> <0>124179e5-82b9-c551-1e88-515ec3bbe4e3</0> <1>5c8246d3-5b9f-16bb-89dc-515ec4674170</1> <2>9d7f4701-81e3-3c90-c743-515ec9580852</2> <3>ea8d97bd-243b-b917-bc15-51764c2b2f34</3> </content> Thanks in advance....

Create array/list of many objects(initially unknown amount) by tag

c#,arrays,list,unity3d,gameobject
I'm currently working on a radar system for my space game, and I am trying to work out how to add gameobjects, by tag, to either a list or array that can then be used in other methods. I can't do this manually because I will be procedurally generating each...

How to use XDocument to get attributes and add them to a List

c#,xml,winforms,list
I am trying to load data from an XML file and add it to a List. The XML file looks like this: and this is my code: public void LoadPayments(List<List<string>> list1, List<List<string>> list2) { try { if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RentData.xml"))) { int count = 0; XDocument doc; using (var reader =...

Using regular expressions on a list that has been converted to a string

python,regex,string,list
Take the following code: >>>foo = ['abcdefgdfsrf1\tword\tfdsaerg32543','2343221d2\tfds\tss'] >>>print re.findall('(\d+)\s+(\w+)\s',str(foo)) [] The regular expression isn't matching correctly because the single quotes surrounding each element of the list are interfering throwing up the quote matching for the entire string. What is the most pythonic way to alter this code so that it...

Update list of items in c#

c#,linq,list,updates
I would like to know if you can suggest me an efficient way to update a list of items in c#. Here is a generic example: If CurrentList is [ {Id: 154, Name: "George", Salary: 10 000} {Id: 233, Name: "Alice", Salary: 10 000}] And NewList is [ {Id: 154,...

How to obtain a random string from a list

python,list,random
My class was recently introduced to lists and our task is to randomly obtain a name from the said list, This is the code i have generated import random Random1 = random.randint(0,7) Class_List = ['Noah','Simone','Ji Ho','Thanh','Nathanial','Soo','Mickel','Tuan','Thuy Linh'] print (ClassList[{}].format(Random1)) However i receive this error Traceback (most recent call last): File...

Get operator operands

list,prolog,operators
I have list: List = [a=3, b=2, c=0]. For example, first element a=3, how can I get value Left = a, Right = 3. Left side is atom and right side is number....

Get element starting with letter from List

java,android,list,indexof
I have a list and I want to get the position of the string which starts with specific letter. I am trying this code, but it isn't working. List<String> sp = Arrays.asList(splited); int i2 = sp.indexOf("^w.*$"); ...

How to get the min of a list with multiple dimensions?

r,list
I'm trying to avoid loops, but not sure how to do this: Let's say I have the following: theList <- list() theList[[1]] <- list(foo = "1", bar = "10") theList[[2]] <- list(bar = "10", foo = "4") theList[[3]] <- list(foo = "-1", bar = "10") How can I call a...

Sorted List for Doubly Linked List

python,list,sorting,doubly-linked-list
I have following 2 classes node and doublylinked list class DLLNode(object): def __Init__ (self, data, prev_node=None, next_node=None): self.data=data self.prev_node=prev_node self.next_node=next_node def __str__(self): return str(self.data) class DoublyLinkedList(object): def __init__(self, head=None, tail=None): self.head=head self.tail=tail self.size=0 def add_to_head(self, data): newNode = DLLNode(data) if self.head==None: self.head=self.tail=newNode self.head.prev_node=self.tail.next_node=None else: self.head.prev_node=newNode...

List of tuples from (a, all b) to (b, all a)

python,list,python-2.7,tuples
I am starting with a list of tuples (a,all b). I want to end with a list of tuples (b,all a). For example: FROM (a1,[b1,b2,b3]) (a2,[b2]) (a3,[b1,b2]) TO (b1,[a1,a3]) (b2[a1,a2,a3]) (b3,[a1] How do I do this using Python 2? Thank you for your help....

UL LI 4 Column List: Center in each column

css,list,navigation
I'm building a footer navigation with four columns: <ul> <li>Top Level 1 <ul> <li>sub 1a</li> <li>sub 1b</li> <li>sub 1c</li> <li>sub 1d</li> </ul> </li> <li>Top Level 2 <ul> <li>sub 2a</li> <li>sub 2b</li> <li>sub 2c</li> <li>sub 2d</li> </ul> </li> .... (repreat 2 more times).... </ul> I have each of the 4 columns...

Is there a difference between new List() and new List(0)

c#,.net,list,memory-management
Is there a difference between new List<T>() and new List<T>(0) ? May be this is a micro-optimization, but the idea is to understund the difference in term of memory allocation....

Continue ordered list numbering automatically

html,list
I wonder how I can have the following ordered list in html 1 Item 1 1A Item 2 1B Item 3 2 Item 4 2A Item 5 2B Item 6 2C Item 7 3 Item 8 ...