Latest Questions tagged Lambda

Browse all latest questions tagged Lambda

55
Votes
Published 27 Oct, 2022
Java - How to replace only the first element of a List<Character> using java streams without making any changes to the rest of the list?

I am getting a List and I want to replace the first value in this list with '$' sign, So that I could use it in some place else. But i don't want the rest of the characters in the list to be misplaced...

64
Votes
Published 19 Sep, 2022
Java - Java access bean methods with LambdaMetafactory

my question is strongly related to Explicit use of LambdaMetafactory in that thread, some very good examples are provided to use the LambdaMetafactory to access a static method of a class; however, I...

65
Votes
Published 01 Oct, 2022
Java - From Anonymous class to lambda expression

When using an anonymous class below , the variable x us called without problem interface Age { int x = 21; void getAge(); } class AnonymousDemo { public static void main(String[]...

16
Votes
Published 04 May, 2022
Python - Efficiently calculate word frequency in a string

I am parsing a long string of text and calculating the number of times each word occurs in Python. I have a function that works but I am looking for advice on whether there are ways I can make it more...

26
Votes
Published 03 Jun, 2022
Python - Lambda data frame reference a value in another column

How do I correctly reference another column value when using a Lambda in a pandas dataframe. dfresult_tmp2['Retention_Rolling_temp'] = dfresult_tmp2['Retention_tmp'].apply(lambda x: x if x['Count...

7
Votes
Published 24 Apr, 2022
Python - Python lambda with regex

When using re.sub() part of re for python, a function can be used for sub if I am not mistaken. To my knowledge it passes in the match to whatever function is passed for example: r = re.compile(r'([A...

27
Votes
Published 03 Oct, 2022
Java - Java 8 stream filter local variable

Obj1 x = null; String key = null; while(it.hasNext()){ x = it.next(); key = x.getKey(); listObject.stream().filter(e -&gt; e.getKey().equals(key)).findFirst().get(); } This is complaining w...

272
Votes
Published 26 Apr, 2022
Python - No Multiline Lambda in Python: Why not?

I've heard it said that multiline lambdas can't be added in Python because they would clash syntactically with the other syntax constructs in Python. I was thinking about this on the bus today and re...

49
Votes
Published 17 Oct, 2022
Java - Convert Java to Kotlin BiFunction containing code

I am trying to convert my Java class into Kotlin. This is the Java code: Observable.just("Stacey") .zipWith(Observable.just(6), (name, age) -&gt; { String text; if(age &lt; 18...

92
Votes
Published 28 Aug, 2022
Python - Use map() function with string

Is there a way to use map() function with a string instead of a list? Or the map() function is meant only to work with lists? For instance, ignoring the content of the lambda function, this code retu...

61
Votes
Published 27 Aug, 2022
Python - SyntaxError: invalid syntax inside map(lambda (x, y)

This is the data in time column: {'Thursday': {'0:00': 1, '23:00': 1, '21:00': 1}, 'Saturday': {'2:00': 1}, 'Monday': {'1:00': 1}} But this code is giving me syntax error : checkin_df['time_clean'...

12
Votes
Published 26 Apr, 2022
Python - Using lambda if condition on different columns in Pandas dataframe

I have simple dataframe: import pandas as pd frame = pd.DataFrame(np.random.randn(4, 3), columns=list('abc')) Thus for example: a b c 0 -0.813530 -1.291862 1.330320 1 -1.066475 0.624...

137
Votes
Published 26 Apr, 2022
Python - Finding the average of a list

I have to find the average of a list in Python. This is my code so far from functools import reduce l = [15, 18, 2, 36, 12, 78, 5, 6, 9] print(reduce(lambda x, y: x + y, l)) I've got it so it adds t...

15
Votes
Published 24 Apr, 2022
Python - Python: union keys from multiple dictionary?

I have 5 dictionaries and I want a union of their keys. alldict = [dict1, dict2, dict3, dict4, dict5] I tried allkey = reduce(lambda x, y: set(x.keys()).union(y.keys()), alldict) but it gave me...

110
Votes
Published 24 Aug, 2022
Java - Difference between final and effectively final

I'm playing with lambdas in Java 8 and I came across warning local variables referenced from a lambda expression must be final or effectively final. I know that when I use variables inside anonymous c...