Linked Questions

175 questions linked to/from List comprehension vs map
4 votes
2 answers
8k views

When should you use map/filter instead of a list comprehension or generator expression?
hekevintran's user avatar
  • 23.8k
12 votes
1 answer
2k views

This question might be sound subjective, but as "the Zen" says, there is (nearly always) one way to preferred, it shouldn't be subjective at the end. What way is the better one? [i.something() for i ...
glglgl's user avatar
  • 91.5k
1 vote
1 answer
13k views

As the question states. map(f, iterable) can be written as [f(x) for x in iterable]. Which is better to use? And why? As an example, I would like to convert a list of strings to int. ip = (...
2 votes
1 answer
4k views

pythonistas: which is faster, where a is something like [ str(x) for x in list(range(100)) ]? ints = map(int, a) Or ints = [ int(x) for x in a ] Assuming a will be a relatively large list of ...
Wells's user avatar
  • 11k
0 votes
4 answers
1k views

When comparing these, which do you think is more intuitive / easier to read? >>> [ord(i) for i in 'some string'] [115, 111, 109, 101, 32, 115, 116, 114, 105, 110, 103] >>> map(ord,'...
tMC's user avatar
  • 19.5k
2 votes
1 answer
496 views

I came across a few articles and StackOverflow discussions where it is usually recommended to use list comprehension while dealing with lists. I usually come across a common loop structure where I ...
1 vote
1 answer
401 views

For map/lambda expression with array a = [1, 2, 3, 4]: f = map(lambda x : x + 32, a) Seems I can simplify write as: f = [x + 32 for x in a] I am wondering whether there is any difference.
BlueDolphin's user avatar
  • 9,765
2 votes
1 answer
294 views

According to the list comprehension doc and this question: squares = [x**2 for x in range(10)] is equivalent to squares = list(map(lambda x: x**2, range(10))) But does Python actually implement list ...
3 votes
1 answer
181 views

I am working through a preparatory course for a Data Science bootcamp and it goes over the lambda keyword and map and filter functions fairly early on in the course. It gives you syntax and how to use ...
1 vote
2 answers
198 views

In my Python program, I was told that this code snippet: listOfNumbers = input() # (This inputs a space separated list of integers) listOfNumbers = listOfNumbers.split() for x in range(0, len(...
cobrexus's user avatar
  • 4,884
0 votes
3 answers
105 views

I have two lists that I'm trying to combine: lst1 = [['arg1', 'arg2']] # this can have more lists, but for simplicity, leaving it as this lst2 = ['arg3', 'arg4'] I want the product of the two lists ...
2 votes
0 answers
128 views

(i5 ivybridge cpu windows 10) Map seems to come out slower every time, for what is a very long list, where it should do well import time l = [2049 for i in range(20000000)] def f(e): return (e * ...
0 votes
0 answers
64 views

I have an application where I have a list of objects, and I need to create a sub list of those objects for which some property is minimum. I naturally started writing for thing in list: type code, and ...
659 votes
19 answers
394k views

I've been learning, working, and playing with Python for a year and a half now. As a biologist slowly making the turn to bio-informatics, this language has been at the very core of all the major ...
814 votes
6 answers
476k views

What is the meaning of _ after for in this code? if tbh.bag: n = 0 for _ in tbh.bag.atom_set(): n += 1

15 30 50 per page
1
2 3 4 5
...
12