tagged [list]

List comprehension vs map

List comprehension vs map Is there a reason to prefer using [map()](https://docs.python.org/3.8/library/functions.html#map) over list comprehension or vice versa? Is either of them generally more effi...

How to remove item from a python list in a loop?

How to remove item from a python list in a loop? I tried this code to remove items from a list: Why isn't `"fren"` removed from `x`?

15 Jan at 05:47

Check if multiple strings exist in another string

Check if multiple strings exist in another string How can I check if any of the strings in an array exists in another string? For example: How can I replace the `if a in s:` line to get the appropriat...

14 Jan at 09:55

How to unzip a list of tuples into individual lists?

How to unzip a list of tuples into individual lists? I have a list of tuples `l = [(1,2), (3,4), (8,9)]`. How can I, succinctly and Pythonically, unzip this list into two independent lists, to get `[ ...

14 Jan at 08:30

Check if two list have the same items

Check if two list have the same items I have two lists of integers, list1 and list2. The elements in the lists are the same, but the order is not important. How can I determine whether these lists are...

7 Jan at 22:2

Common elements comparison between 2 lists

Common elements comparison between 2 lists Given two input lists, how can I create a list of the elements that are common to both inputs? For example: for inputs `[1,2,3,4,5,6]` and `[3,5,7,9]`, the r...

6 Jan at 00:57

Python list rotation

Python list rotation I'd like to rotate a Python list by an arbitrary number of items to the right or left (the latter using a negative argument). Something like this: How might this be done?

5 Jan at 08:37

How can I add to a List's first position?

How can I add to a List's first position? I just have a `List` and I would like to add an item to this list but at the first position. `MyList.add()` adds the item as the last. How can I add it as the...

4 Jan at 18:34

Replace an object in a list of objects

Replace an object in a list of objects In C#, if I have a `List`, and I have an object of type `T`, how can I replace a specific item in the `List` with the object of type `T`? Here is what I have tri...

Get difference between two lists with Unique Entries

Get difference between two lists with Unique Entries I have two lists in Python: Assuming the elements in each list are unique, I want to create a third list with items from the first list which are n...

How to insert an item into a key/value pair object?

How to insert an item into a key/value pair object? I just need to be able to insert a key/value pair into an object at a specific position. I'm currently working with a Hashtable which, of course, do...

20 Dec at 00:54

IEnumerable vs IReadonlyCollection vs ReadonlyCollection for exposing a list member

IEnumerable vs IReadonlyCollection vs ReadonlyCollection for exposing a list member I have spent quite a few hours pondering the subject of exposing list members. In a similar question to mine, Jon Sk...

18 Dec at 20:57

Converting a String to a List of Words?

Converting a String to a List of Words? I'm trying to convert a string to a list of words using python. I want to take something like the following: Then convert to something like this : Notice the om...

10 Dec at 15:16

ICollection<T> Vs List<T> in Entity Framework

ICollection Vs List in Entity Framework I only watched a few webcasts before I went head first in to designing a few Entity Framework applications. I really didn't read that much documentation and I f...

How to remove item from list in C#?

How to remove item from list in C#? I have a list stored in resultlist as follows: It looks something like this: How do I remove ID 2 from the list?

9 Dec at 07:22

Python's most efficient way to choose longest string in list?

Python's most efficient way to choose longest string in list? I have a list of variable length and am trying to find a way to test if the list item currently being evaluated is the longest string cont...

5 Dec at 14:13

Convert contents of DataGridView to List in C#

Convert contents of DataGridView to List in C# What is the best way to grab the contents of a DataGridView and place those values into a list in C#?

27 Nov at 07:40

How do I get the number of elements in a list (length of a list) in Python?

How do I get the number of elements in a list (length of a list) in Python? How do I get the number of elements in the list `items`?

13 Oct at 18:5

Print array without brackets and commas

Print array without brackets and commas I'm porting a Hangman game to Android and have met a few problems. The original Java program used the console, so now I have to somehow beautify the output so t...

12 Oct at 21:13

Why does this iterative list-growing code give IndexError: list assignment index out of range? How can I repeatedly add (append) elements to a list?

Why does this iterative list-growing code give IndexError: list assignment index out of range? How can I repeatedly add (append) elements to a list? I tried writing some code like: But I get an error ...

11 Oct at 03:37

Removing duplicates in lists

Removing duplicates in lists How can I check if a list has any duplicates and return a new list without duplicates?

Find and replace string values in list

Find and replace string values in list I got this list: What I would like is to replace `[br]` with some fantastic value similar to `` and thus getting a new list:

7 Oct at 14:3

Convert an enum to List<string>

Convert an enum to List How do I convert the following Enum to a List of strings? I couldn't find this exact question, this [Enum to List](https://stackoverflow.com/questions/1167361/how-do-i-convert-...

4 Oct at 02:22

How do I split a list into equally-sized chunks?

How do I split a list into equally-sized chunks? How do I split a list of arbitrary length into equal sized chunks? --- [How to iterate over a list in chunks](https://stackoverflow.com/q/434287) [Spli...

2 Oct at 01:6

Get list from pandas dataframe column or row?

Get list from pandas dataframe column or row? I have a dataframe `df` imported from an Excel document like this: ``` cluster load_date budget actual fixed_price A 1/1/2014 1000 4000 Y A 2/1/2014...

22 Sep at 03:38