Posts

Showing posts with the label Lambda

[Python] Code Example 6 - Lambda & filter function (2)

[Source Code] # Select retweets from the Twitter DataFrame: result result = filter(lambda x : x[0:2] == 'RT', tweets_df['text']) # Create list from filter object result: res_list res_list = list(result) # Print all retweets in res_list for tweet in res_list:     print(tweet) [Output] ========================================== <script.py> output:     RT @bpolitics: .@krollbondrating's Christopher Whalen says Clinton is the weakest Dem candidate in 50 years https://t.co/pLk7rvoRSn https:/…     RT @HeidiAlpine: @dmartosko Cruz video found.....racing from the scene.... #cruzsexscandal https://t.co/zuAPZfQDk3     RT @AlanLohner: The anti-American D.C. elites despise Trump for his America-first foreign policy. Trump threatens their gravy train. https:…     RT @BIackPplTweets: Young Donald trump meets his neighbor  https://t.co/RFlu17Z1eE     RT @trumpresearch: @WaitingInBagd...

[Python] Code Example 5 - Lambda & filter function (1)

[Source Code] # Create a list of strings: fellowship fellowship = ['frodo', 'samwise', 'merry', 'pippin', 'aragorn', 'boromir', 'legolas', 'gimli', 'gandalf'] # Use filter() to apply a lambda function over fellowship: result result = filter(lambda member: len(member) > 6, fellowship) # Convert result to a list: result_list result_list = list(result) # Print result_list print(result_list) [Output] ========================================== ['samwise', 'aragorn', 'boromir', 'legolas', 'gandalf']