如何返回第一次出现的数据
- 编程技术
- 2025-02-02 01:51:51
- 1

要返回第一次出现的数据,你可以使用不同的编程语言和方法,以下是一些常见语言的示例: Python```pythondef first_occurrence(data,...
要返回第一次出现的数据,你可以使用不同的编程语言和方法,以下是一些常见语言的示例:
Python
```python
def first_occurrence(data, target):
for item in data:
if item == target:
return item
return None
示例
data = [1, 2, 3, 4, 5, 3, 2, 1]
target = 3
print(first_occurrence(data, target)) 输出: 3
```
JavaScript
```javascript
function firstOccurrence(data, target) {
for (let item of data) {
if (item === target) {
return item;
本文由夕逆IT于2025-02-02发表在夕逆IT,如有疑问,请联系我们。
本文链接:http://www.xinin56.com/bian/425968.html
本文链接:http://www.xinin56.com/bian/425968.html
上一篇:如何使自己演讲不紧张