list interview questions
Top list frequently asked interview questions
What are the options to clone or copy a list in Python?
Using new_list = my_list
then modifies new_list
every time my_list
changes. Why is this?
Source: (StackOverflow)
I have a class called Order
which has properties such as OrderId
, OrderDate
, Quantity
, and Total
. I have a list of this Order
class:
List<Order> objListOrder = new List<Order>();
GetOrderList(objListOrder); // fill list of orders
Now I want to sort the list based on one property of the Order
object, for example I need to sort it by the order date or order id.
How can i do this in C#?
Source: (StackOverflow)
Let say I have a List<T> abc = new List<T>;
inside a class public class MyClass<T>//...
.
Later, when I initialize the class, the T
becomes MyTypeObject1
. So I have a generic list, List< MyTypeObject1 >
.
I would like to know, what type of object the list of my class contain, e.g. the list called abc
contain what type of object?
I cannot do abc[0].GetType();
because the list might contain zero elements. How can I do it?
Source: (StackOverflow)
Say that I have LINQ query such as:
var authors = from x in authorsList
where x.firstname == "Bob"
select x;
Given that authorsList
is of type List<Author>
, how can I delete the Author
elements from authorsList
that are returned by the query into authors
?
Or, put another way, how can I delete all of the firstname's equalling Bob from authorsList
?
Note: This is a simplified example for the purposes of the question.
Source: (StackOverflow)
This has always confused me. It seems like this would be nicer:
my_list = ["Hello", "world"]
print my_list.join("-")
# Produce: "Hello-world"
Than this:
my_list = ["Hello", "world"]
print "-".join(my_list)
# Produce: "Hello-world"
Is there a specific reason it does it like this?
Source: (StackOverflow)
How do I concatenate two lists in Python?
Example:
listone = [1,2,3]
listtwo = [4,5,6]
Expected outcome:
joinedlist == [1, 2, 3, 4, 5, 6]
Source: (StackOverflow)
items = []
items.append("apple")
items.append("orange")
items.append("banana")
# FAKE METHOD::
items.amount() # Should return 3
How do I do it right?
Source: (StackOverflow)
Does anyone know how to access the index itself for a list like this:
ints = [8, 23, 45, 12, 78]
When I loop through it using a for loop, how do I access the loop index, from 1 to 5 in this case?
Source: (StackOverflow)
Do you have a good explanation (with references) on Python's slice notation? To me, this notation needs a bit of picking up. It looks extremely powerful, but I haven't quite got my head around it and am looking for a good guide.
Source: (StackOverflow)
For a list ["foo", "bar", "baz"]
and an item in the list "bar"
, what's the cleanest way to get its index (1) in Python?
Source: (StackOverflow)