Topic on Project:Support desk

Get Unique List Items?

2
Summary by Johnywhy

Although there may be other methods, Extension:Arrays is tiny and works great. Works fine on MW 1.30. Hopefully, will continue to work with future versions of MW.

One handy thing about Extension:Arrays is, you can achieve uniques in one step, when the array is defined, by using the 'unique' option. You don't have to perform #arrayunique as a separate step.

Example of passing output of DPL3 to Arrays, and then printing the array, with each array element passed as a parameter to a template:

Note the use of nowiki/ before an embedded newline and bullet, to get proper bullets.

{{#arraydefine:aryTags
    |{{#dpl: 
                noresultsheader=  
                |uses = Template:Tag
                |format=,,,
                |include = {Tag}:1
                |secseparators = ·
                |multisecseparators = ·
            }}
    |·
    |unique
       }}

{{#arrayprint:aryTags|<br/>|@@@@|<nowiki/>
        * {{TagLink|@@@@}} }}
Johnywhy (talkcontribs)

Say i have a list of items, with repeats, and i want a list of the unique items:

Chocolate·Ostrich·Ostrich·Apples·Pears·Green·Chocolate·Ostrich·Apples·Blue·CommonGround·Blue·CommonGround

It seems there are two stable, but unmaintained, extensions that may be able to do it.

Extension:HashTables#hashdefine

Extension:Arrays#arrayunique

Is there any other method or extension that can do this?

Johnywhy (talkcontribs)

The handy thing about Extension:Arrays is, you can achieve uniques in one step, when the array is defined, by using the 'unique' option. You don't have to perform #arrayunique as a separate step.