开发者社区> 问答> 正文

从广播列表中删除元素

我有一个URL列表,例如:

www.google.com
www.yahoo.fr
www.stackoverflow.com
我想删除包含字符串“ oo”和“ flow”的所有URL 。

我做了一个python函数:

def my_function(param1,param2,
param3,param4,liste_to_delete,liste2_to_delete):

 status=True
 SQL_CONSTANT = "url not like '%"
 URL_SEP = ";"
 # getFirstList
 broadcastListe1String =""
 listtodelete = liste2_to_delete.split(URL_SEP)
 for url in listtodelete:
     broadcastListe1String = SQL_CONSTANT + url + "%'"
     if(listtodelete.index(url) != len(listtodelete) -1):
         broadcastListe1String = broadcastListe1String + " AND "
 my_broadcast = sc.broadcast(broadcastListe1String)

然后我做了:

DataFrame= my_DataFrame.where(my_broadcast.value)
这个函数从我列表中的第二个元素开始,它不会占用我列表中的第一个元素。

如何更改我的功能还删除列表中的第一个元素?

展开
收起
社区小助手 2018-12-21 11:38:54 1656 0
1 条回答
写回答
取消 提交回答
  • 社区小助手是spark中国社区的管理员,我会定期更新直播回顾等资料和文章干货,还整合了大家在钉群提出的有关spark的问题及回答。

    可以使用这样的filter函数:

    filter(lambda x: 'oo' not in x and 'flow' not in x, lst)
    例如:

    lst = ['www.google.com',

       'www.yahoo.fr',
       'www.stackoverflow.com',
       'www.duckduck.com',
       'www.amazon.com',
      ]
    

    filtered_lst = filter(lambda x: 'oo' not in x and 'flow' not in x, lst)

    filtered_lst = ['www.duckduck.com', 'www.amazon.com']

    要么:

    lst = ['www.google.com',

       'www.yahoo.fr',
       'www.stackoverflow.com',
       'www.duckduck.com',
       'www.amazon.com',
      ]
    

    ex_words = ['oo', 'flow']

    filterd_lst = filter(lambda x: all(w not in x for w in ex_words), lst)

    filtered_lst = ['www.duckduck.com', 'www.amazon.com']

    2019-07-17 23:23:19
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载