从C#中的唯一(独立)元素获取索引 - c#

我想获得独立元素的索引。元素本身有可能出现在列表中的频率更高(一个接一个或多个)。单个元素的指示是,前任和后继不等于当前元素。有没有一种优雅的方法可以做到这一点?

例:

1.  A
2.  A
3.  A
4.  B
5.  B
6.  A
7.  B
8.  B
9.  C
10. B

结果:

6,9,10

参考方案

简单遍历项目并检查条件

char[] items = { 'A', 'A', 'A', 'B', 'B', 'A', 'B', 'B', 'C', 'B' };
for (int i = 0; i < items.Length; i++)
{
    if (i == 0)
    {
        // in case of the first element you only have to validate against the next
        if (items[i] != items[i + 1])
            Console.WriteLine(i + 1);
    }
    else if (i == items.Length - 1)
    {
        // in case of the last element you only have to validate against the previous       
        if (items[i] != items[i - 1])
            Console.WriteLine(i + 1);
    }
    else
    {
        // validate against previous and next element
        if (items[i] != items[i - 1] && items[i] != items[i + 1])
            Console.WriteLine(i + 1);
    }
}

https://dotnetfiddle.net/kWmqu7

将字符串分配给numpy.zeros数组[重复] - python

This question already has answers here: Weird behaviour initializing a numpy array of string data                                                                    (4个答案)         …

TypeError:'str'对象不支持项目分配,带有json文件的python - python

以下是我的代码import json with open('johns.json', 'r') as q: l = q.read() data = json.loads(l) data['john'] = '{}' data['john']['use…

R'relaimpo'软件包的Python端口 - python

我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。

如何用'-'解析字符串到节点js本地脚本? - python

我正在使用本地节点js脚本来处理字符串。我陷入了将'-'字符串解析为本地节点js脚本的问题。render.js:#! /usr/bin/env -S node -r esm let argv = require('yargs') .usage('$0 [string]') .argv; console.log(argv…

如果我得到url(''),我该如何使用另一个URL - javascript

我是新手,正在写这篇文章,但是如果源上没有图像,那么我只有空白。有人可以告诉我,如果我正在获取背景图像,如何获取/images/no-image.jpg:url();这是我的代码:<div class="uk-clearfix uk-position-relative"> <div class="recipeb…