logo
down
shadow

How to get the unique numbers of a list in a new list?


How to get the unique numbers of a list in a new list?

By : Shubham Singh
Date : November 18 2020, 07:00 PM
fixed the issue. Will look into that further I have this list: , Use a Counter object.
code :
>>> from collections import Counter
>>> from itertools import chain
>>> my_list = [{1,2,3,4}, {3,4,5}, {2,6}]
>>> set(k for k,v in Counter(chain.from_iterable(my_list)).items() if v == 1)
set([1, 5, 6])
>>> list(chain.from_iterable(my_list))
[1, 2, 3, 4, 3, 4, 5, 2, 6]
>>> Counter(chain.from_iterable(my_list))
Counter({2: 2, 3: 2, 4: 2, 1: 1, 5: 1, 6: 1})


Share : facebook icon twitter icon
Java: Create unique List from an existing List keeping index numbers constant

Java: Create unique List from an existing List keeping index numbers constant


By : Seboy
Date : March 29 2020, 07:55 AM
around this issue I have two ArrayLists. , This is the full solution
code :
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
public static void main(String[] args) {

    ArrayList<String> date = new ArrayList<>();
    date.add("1");
    date.add("2");
    date.add("2");
    date.add("3");
    System.out.println(date);

    ArrayList<Integer> value = new ArrayList<>();
    value.add(1);
    value.add(2);
    value.add(4);
    value.add(3);
    System.out.println(value);

    new MyCls().createList(date, value);

}
ArrayList uniqueDate = new ArrayList<String>();
ArrayList averageValue = new ArrayList<Integer>();
LinkedHashMap store = new LinkedHashMap<String, CountEntry>();

class CountEntry {
    int value;
    int count;

    CountEntry() {
    }

    CountEntry(int v, int c) {
        value = v;
        count = c;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}

public void createList(ArrayList<String> date, ArrayList<Integer> value) {
    for (int i = 0; i < date.size(); i++) {
        CountEntry tmp = (CountEntry) store.get(date.get(i));

        if (tmp == null) {
            store.put(date.get(i), new CountEntry(value.get(i), 1));
        } else {
            int tmpVal = tmp.getValue();
            int tmpCount = tmp.getCount();
            store.put(date.get(i), new CountEntry(value.get(i) + tmpVal, ++tmpCount));
        }
    }

    ArrayList<String> uniqueDate = new ArrayList<String>(store.keySet());
    ArrayList<CountEntry> tempAvgList = new ArrayList<CountEntry>(store.values());

    for (CountEntry ce : tempAvgList) {

        averageValue.add(ce.getValue() / ce.getCount());

    }
    System.out.println("Output");
    System.out.println(uniqueDate);
    System.out.println(averageValue);
}
[1, 2, 2, 3]
[1, 2, 4, 3]
Output
[1, 2, 3]
[1, 3, 3]
Add unique Id to list of numbers - VBA

Add unique Id to list of numbers - VBA


By : BlueTurtle
Date : March 29 2020, 07:55 AM
This might help you I know you asked for vba, but a simple formula will give you the desired output.
In B1 put:
code :
=A1& "-" &TEXT(COUNTIF($A$1:A1,A1),"000")
Sub test2()
    Dim rng As Range
    Dim rngcnt As Range
    Dim firstrow As Long
    Dim lastrow As Long
    Dim columnNumber As Long
    Dim ws As Worksheet

    Set ws = Worksheets("Sheet15") 'change to your sheet
    firstrow = 1 'change to your first row of data
    columnNumber = 1 'change to the column number

    With ws
        lastrow = .Cells(.Rows.Count, columnNumber).End(xlUp).Row
        For i = firstrow To lastrow
            .Cells(i, columnNumber + 1) = .Cells(i, columnNumber) & "-" & Format(Application.WorksheetFunction.CountIf(.Range(.Cells(firstrow, columnNumber), .Cells(i, columnNumber)), .Cells(i, columnNumber)), "000")
        Next i
    End With

End Sub
Generate a list of unique random numbers where the number should not be same as index of number in list using kdb

Generate a list of unique random numbers where the number should not be same as index of number in list using kdb


By : user3490643
Date : March 29 2020, 07:55 AM
will be helpful for those in need There are probably a few ways to do go about this. I came up with this:
code :
q){$[any (r:neg[x]?x)=til x;.z.s x;r]}5
3 2 4 0 1
q){$[any (r:neg[x]?x)=til x;.z.s x;r]}5
2 0 4 1 3
How do i make a list of random unique numbers that avoid using numbers from an already existing list of random unique nu

How do i make a list of random unique numbers that avoid using numbers from an already existing list of random unique nu


By : Soumya Subhadarshi
Date : March 29 2020, 07:55 AM
around this issue random solution
If you want to only use the random module, you can use:
code :
import random

nums = random.sample(range(1,35), 10)

winning_numbers = nums[:7]
bonus_numbers = nums[7:]

>>> winning_numbers
[2, 23, 29, 34, 26, 16, 13]

>>> bonus_numbers
[8, 4, 19]
import numpy as np

nums = np.random.choice(range(1,35), 10, replace=False)

winning_numbers = nums[:7]
bonus_numbers = nums[7:]


>>> winning_numbers
array([27,  4, 17, 30, 32, 21, 23])

>>> bonus_numbers
array([15, 13, 18])
Given an array of unique numbers, list the combination of numbers which sum equals to given integer

Given an array of unique numbers, list the combination of numbers which sum equals to given integer


By : Justin C
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You could use a temporary array and the index and iterate the next index by either taking the actual value or not.
code :
function subsetSum(array, sum) {

    function iter(index, temp, s) {
        if (s === sum) return result.push(temp.slice());              // exit sum found
        if (index >= array.length) return;                            // exit index over
        iter(index + 1, temp.concat(array[index]), s + array[index]); // take value
        iter(index + 1, temp, s);                                     // omit value
    }

    var result = [];
    iter(0, [], 0);
    return result;
}

console.log(subsetSum([4, 2, 8, 11, 14, 6, 1], 20).map(a => a.join(' ')));
Related Posts Related Posts :
  • read a binary file (python)
  • Number Sequence in MySQL
  • Unit testing in python?
  • s/mime v3 with M2Crypto
  • Using wget via Python
  • Running a python script in background from a CGI
  • Edit Distance in Python
  • how to read url data
  • A RAM error of big array
  • Python: For loop problem
  • How do I create a list with 256 elements?
  • RAW Image processing in Python
  • access django session from a decorator
  • Multi-Threaded data insertion in MySQL using python
  • Making all variables accessible to namespace
  • What are the differences among sqlite3 from python2.5, pysqlite and apsw
  • Detect marker with opencv and python
  • Python ctypes and dynamic linking
  • Downloading a directory tree with ftplib
  • ImportError: No Module named simplejson
  • Pre-generating GUIDs for use in python?
  • `ipython` tab autocomplete does not work on imported module
  • Matching blank entries in django queryset for optional field with corresponding ones in a required field
  • Control VLC from Python in Windows
  • Return unicode string from python via ajax
  • Dynamically customize django admin columns?
  • Any way to add tabbed forms in django administration site?
  • Python / SQLite - database locked despite large timeouts
  • Encoding in XML declaration python
  • deletion of folders
  • Python Mindstorms RCX
  • Regex to split on successions of newline characters
  • Unicode filename to python subprocess.call()
  • Removing non-breaking spaces from strings using Python
  • Is there a way to backup everything in an app-engine blobstore?
  • Process a set of files from a source directory to a destination directory in Python
  • How to know if optparse option was passed in the command line or as a default
  • Rewriting a for loop in pure NumPy to decrease execution time
  • Comparing a time delta in python
  • Find next lower item in a sorted list
  • MySQLdb not INSERTING, _mysql does fine
  • Scipy Negative Distance? What?
  • What are the common patterns in web programming?
  • Percent signs in windows path
  • How to add a random number to a subsection of a numpy array?
  • How to generate all the values of an iterable besides the last few?
  • Searching by both class and range in XPath
  • Python code execution in Perl interpreter
  • Best Way to Include Variable in Python3
  • Serialize the @property methods in a Python class
  • What is the most platform- and Python-version-independent way to make a fast loop for use in Python?
  • Good way to edit the previous defined class in ipython
  • Bounced email on Google App Engine
  • Search jpeg files using python
  • Dynamically create class attributes
  • python unichr problem
  • Python beginner, strange output problem
  • Python: Finding a value in 1 list and finding that corresponding index in another list
  • can't install mysqlclient on mac os x mojave
  • Error indicates flattened dimensions when loading pre-trained network
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk