# Assign a number to items in a list with same value

**URL:** <https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223>\
**Category:** Revit\
**Tags:** dynamo\
**Created:** [December 11, 2020, 11:39am UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223 "2020-12-11T11:39:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuele.fuda](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@samuele.fuda](https://forum.dynamobim.com/u/samuele.fuda)\
**Post date:** [December 11, 2020, 11:39am UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/1 "2020-12-11T11:39:46Z")

</div>

Hi everyone,

Using node “SharedParameters.Info” I have a list of items that indicates the shared parameters groups of shared parameters in a project. So I have a list of 435 items, namely 435 shared parameters. With node “List.UniqueItems” I found 16 unique shared parameters groups.  
I would like to assign a number from 1 to 16 to each group and then list the 435 shared parameters with the corrisponding numer. So, for example, SP group named “PG\_STRUCTURAL” corresponds to 1, “PG\_IDENTITY\_DATA” corresponds to 2, etc.  
I really don’t know how to tackle this problem, as my knowledge of dynamo is pretty basic and I didn’t find anything on the forum to solve this.

Thanks in advance!

 ![Shared_Parameters_Groups](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/7/c772e940caa935ea79811f991ad4a7823e0cb7c2.jpeg)

---

<div class="post-metadata">

**Author:** ![bvs1982](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bvs1982](https://forum.dynamobim.com/u/bvs1982)\
**Post date:** [December 11, 2020, 11:51am UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/2 "2020-12-11T11:51:53Z")

</div>

What is you goal with this?

Was about to say this 👇. Francois beat me to it.

---

<div class="post-metadata">

**Author:** ![Francois\_Labonne](https://avatars.discourse-cdn.com/v4/letter/f/bcef8e/32.png) [@Francois\_Labonne](https://forum.dynamobim.com/u/Francois_Labonne)\
**Post date:** [December 11, 2020, 11:54am UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/3 "2020-12-11T11:54:32Z")

</div>

Hi @samuele.fuda  
Did you try **List.GroupByKey**?

---

<div class="post-metadata">

**Author:** ![samuele.fuda](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@samuele.fuda](https://forum.dynamobim.com/u/samuele.fuda)\
**Post date:** [December 11, 2020, 11:57am UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/4 "2020-12-11T11:57:25Z")

</div>

The general goal of this script is to create the shared parameters file from a rvt file of which I don’t have the SP .txt file. In the SP file for each parameter is indicated the SP group, which is represented by a progressive number.

---

<div class="post-metadata">

**Author:** ![samuele.fuda](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@samuele.fuda](https://forum.dynamobim.com/u/samuele.fuda)\
**Post date:** [December 11, 2020, 12:02pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/5 "2020-12-11T12:02:13Z")

</div>

I have tried it but the two list have a different number of items, so it doesn’t work. Plus, if I am not wrong, this node would group the items by entry and I want to mantain the number of items in the original list of shared parameters, just with a number instead of the name.

---

<div class="post-metadata">

**Author:** ![Francois\_Labonne](https://avatars.discourse-cdn.com/v4/letter/f/bcef8e/32.png) [@Francois\_Labonne](https://forum.dynamobim.com/u/Francois_Labonne)\
**Post date:** [December 11, 2020, 12:04pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/6 "2020-12-11T12:04:00Z")

</div>

![group_by_key](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/9/29618ce9b53f03f5bac860ea94b6c613b4f65447.png)

---

<div class="post-metadata">

**Author:** ![bvs1982](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bvs1982](https://forum.dynamobim.com/u/bvs1982)\
**Post date:** [December 11, 2020, 12:30pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/7 "2020-12-11T12:30:47Z")

</div>

It might be better to start of with Get Shared Parameter from the Genius.Loci package.

 ![Knipsel2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/8/f8c74211f27faa910aa7af2188731739b9e8fe49.png)

I also think the way to go IS List.GroupByKey. Go from there and see what you can come up with.  
Then when you get stuck we can help you from there.

---

<div class="post-metadata">

**Author:** ![samuele.fuda](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@samuele.fuda](https://forum.dynamobim.com/u/samuele.fuda)\
**Post date:** [December 11, 2020, 1:48pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/8 "2020-12-11T13:48:57Z")

</div>

first of all, thanks for your help. I’ve tried Get Shared Parameter from the Genius.Loci package, but it doesn’t work because this node gets the parameters from the shared parameter file, which I don’t have, I am trying to create it from this script. Then I tried the List.GroupbyKey as you can see in the image attached. Probably I didn’t get how it works, but if I try to associate a number to each item in the list i just get a list in which the numbers from 1 to 16 are listed in order and after the sixteenth entry it repeat 16 unitlll the end. Instead I would like that for each of the sixteen group name is associated a number.  
I’ve attached also a couple of images to clarify what I’m trying to say. Thanks Again!

 ![ListGroupbyKey.PNG](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/2/724f0bae79f41e7f9d753e3eeff61176fa9e9dae.jpeg) ![Group](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/a/4a75f53324936f66a40b2523bf7e35344505afb8.jpeg) ![Shared_Parameter_List](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/b/3be0ebc0b9b605410c9681274faa597efcdfa92f.jpeg)

---

<div class="post-metadata">

**Author:** ![bvs1982](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bvs1982](https://forum.dynamobim.com/u/bvs1982)\
**Post date:** [December 11, 2020, 1:58pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/9 "2020-12-11T13:58:08Z")

</div>

> [@samuele.fuda](#):
>
> The general goal of this script is to create the shared parameters file from a rvt file of which I don’t have the SP .txt file. In the SP file for each parameter is indicated the SP group, which is represented by a progressive number.

So when you create the new SP file you also wanna rename the parameter and parameter groups (with a number as a prefix).

But for your first question this should work 👇

![Knipsel2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/8/a8e94aa0c7738edb08aab76b9468cf33be5020c6.png)

---

<div class="post-metadata">

**Author:** ![Francois\_Labonne](https://avatars.discourse-cdn.com/v4/letter/f/bcef8e/32.png) [@Francois\_Labonne](https://forum.dynamobim.com/u/Francois_Labonne)\
**Post date:** [December 11, 2020, 2:06pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/10 "2020-12-11T14:06:54Z")

</div>

@samuele.fuda  
To replace the values you can use a dictionary

 ![replace](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/a/7ad160d2843777a4dde49438d305000b59aba76d.png)  
 ![replace_in_dictionary](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/5/7529e07bfd1794542075f658050d752d3c759ee0.png)  
[replace\_in\_dictionary.dyn](https://forum.dynamobim.com/uploads/short-url/h5cP58miKYTzYTKgVfiusHnrTEe.dyn) (41.4 KB)

---

<div class="post-metadata">

**Author:** ![samuele.fuda](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@samuele.fuda](https://forum.dynamobim.com/u/samuele.fuda)\
**Post date:** [December 11, 2020, 2:09pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/11 "2020-12-11T14:09:21Z")

</div>

Partially yes, I want to assign A group ID (a number) to each parameter group. This because without a group ID the shared parameter file doesn’t work (see the attached file of a shared parameter txt file). I guess that i could just assign a unique group to all shared parameters, but it wont’ be ideal.

Sorry forgot the image

 ![tempsnip](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/a/5aefc9060bc5df3febcf98b11df8cebd1548e9a3.png)

---

<div class="post-metadata">

**Author:** ![bvs1982](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bvs1982](https://forum.dynamobim.com/u/bvs1982)\
**Post date:** [December 11, 2020, 2:15pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/12 "2020-12-11T14:15:28Z")

</div>

Can you please try my suggestion first?

![Knipsel2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/8/a8e94aa0c7738edb08aab76b9468cf33be5020c6.png)

---

<div class="post-metadata">

**Author:** ![Francois\_Labonne](https://avatars.discourse-cdn.com/v4/letter/f/bcef8e/32.png) [@Francois\_Labonne](https://forum.dynamobim.com/u/Francois_Labonne)\
**Post date:** [December 11, 2020, 3:18pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/13 "2020-12-11T15:18:02Z")

</div>

I agree List.GroupByKey should be the easier way

 ![replace_with_group_by_key](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/8/08382c492a84526bcef19a7550f7b873eee07883.png)  
(i like doing dictionary because the hierarchy is not lost and it can be use for other parameters…)

---

<div class="post-metadata">

**Author:** ![Francois\_Labonne](https://avatars.discourse-cdn.com/v4/letter/f/bcef8e/32.png) [@Francois\_Labonne](https://forum.dynamobim.com/u/Francois_Labonne)\
**Post date:** [December 11, 2020, 3:34pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/14 "2020-12-11T15:34:35Z")

</div>

In that case the keys have to come from the inputs values, when they are grouped you can then set the values

---

<div class="post-metadata">

**Author:** ![samuele.fuda](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@samuele.fuda](https://forum.dynamobim.com/u/samuele.fuda)\
**Post date:** [December 11, 2020, 3:54pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/15 "2020-12-11T15:54:59Z")

</div>

Hi,

I have tried your solution and it almost works, but at the end it seems that the replacing values with the dictionary are not correct. As you can see in the image attached the values of the shared parameter don’t correspond to the values of the groups name. There is something that i’m missing?

 ![EP_Labonne_Solution](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/4/e46dc4ac92dc75a3d42866ff11e79fe0730f15fa.png)

---

<div class="post-metadata">

**Author:** ![samuele.fuda](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@samuele.fuda](https://forum.dynamobim.com/u/samuele.fuda)\
**Post date:** [December 11, 2020, 3:57pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/16 "2020-12-11T15:57:37Z")

</div>

I’ve tried your solution and it works, but not as I intended. It gives me the shared paramaters divided by parameter group, but in this way i lose the original index order

---

<div class="post-metadata">

**Author:** ![Francois\_Labonne](https://avatars.discourse-cdn.com/v4/letter/f/bcef8e/32.png) [@Francois\_Labonne](https://forum.dynamobim.com/u/Francois_Labonne)\
**Post date:** [December 11, 2020, 5:04pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/17 "2020-12-11T17:04:50Z")

</div>

@samuele.fuda  
Could you check the dictionary by scrolling down the result of the node, is there something weird here ?  
Is there really a shared group named INVALID ?

---

<div class="post-metadata">

**Author:** ![samuele.fuda](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@samuele.fuda](https://forum.dynamobim.com/u/samuele.fuda)\
**Post date:** [December 11, 2020, 6:25pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/18 "2020-12-11T18:25:10Z")

</div>

Yes apparently there is a entry named INVALID. Unfortunately I can’t reach out to the people who originally made this project. This is also the reason why I don’t have the shared parameter file.

---

<div class="post-metadata">

**Author:** ![Francois\_Labonne](https://avatars.discourse-cdn.com/v4/letter/f/bcef8e/32.png) [@Francois\_Labonne](https://forum.dynamobim.com/u/Francois_Labonne)\
**Post date:** [December 11, 2020, 6:30pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/19 "2020-12-11T18:30:56Z")

</div>

it made me doubting, but INVALID is a valid entry 🙄  
i replicate the error with my graph, so i think the error doesn’t come from the inputs but something is wrong with my graph, i am checking…

---

<div class="post-metadata">

**Author:** ![Francois\_Labonne](https://avatars.discourse-cdn.com/v4/letter/f/bcef8e/32.png) [@Francois\_Labonne](https://forum.dynamobim.com/u/Francois_Labonne)\
**Post date:** [December 11, 2020, 6:46pm UTC](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223/20 "2020-12-11T18:46:02Z")

</div>

@samuele.fuda  
Here it is !

 ![missing_node](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/a/8a56ca19fcd2f0ceca9528a070467ce703e0b147.png)  
I am sorry for the error…  
I forgot to convert the keys (strings) to number, so when sorting it goes 0,1,10,2,3,… instead of 0,1,2,3,4…  
As i worked with a generic sample with a list\<10 i missed it…sorry again.

[Next page](https://forum.dynamobim.com/t/assign-a-number-to-items-in-a-list-with-same-value/58223.md?page=2)
