python - find elements in list that fullfill condition WHICH needs the previous element
问题描述
So I want to test if a list contains a element which fullfills a condition for which the previous element is needed. E.g.:
liste = [1,3,5,2,6,4,7,1,3,5,2,3,4,7]
And now I want to test for two numbers if they occur consecutive in the list (e.g. find(liste, 3, 4)
would give out TRUE if 3 comes directly before 4 in the array liste, otherwise FALSE)
What gives me problems is that a number occurs multiple times in the array. And I need to test it for every occurence. Any ideas?
FYI: I have implemented it in javascript but now want it in python. In javascript I use:
!!liste.find((element, idx) => idx > 0 && liste[idx-1] == 3 && element == 4)
But I have trouble translating that into pyhton...
解决方案
推荐阅读
- javascript - [webpack 新手] webpack 清单插件的自动前缀问题
- html - Reactjs - 热点 robocop 类型的应用程序
- ruby-on-rails - 如何解决将rails数据导出到csv的日文字符的编码问题?
- c++ - 为 C++ 映射做编号列表时的 int 或 index
- python - 如何在数据帧上使用类似 Count_values 的东西?
- javascript - 创建一个待办事项列表应用程序并停留在帖子上
- javascript - 打字稿反应 createContext 和 useState
- sql - 如何在 PostgreSQL 中设计特定于上下文的权限/角色系统?
- networking - 如何在 Windows10 中使用 Cuckoo 使用 Windump
- python - 特斯拉 api 股价