User Profile

Collapse

Profile Sidebar

Collapse
GTXY20
GTXY20
Last Activity: Apr 14 '08, 07:37 PM
Joined: Oct 1 '07
Location: Toronto
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • GTXY20
    replied to Count unique values in ArrayList C#
    in .NET
    Further I was able to do the same using a hashtable:

    Code:
    Hashtable items = new Hashtable();
    if (!items.Contains(itemfromlist))
           items.Add(itemfromlist, 1);
    else
           items[itemfromlist] = (int) items[itemfromlist]+1
    See more | Go to post

    Leave a comment:


  • GTXY20
    replied to Count unique values in ArrayList C#
    in .NET
    The list of values were kept in a dictionary so I have a dictionary with a key value pair where the value is a list of items.

    Code:
    data = new Dictionary<string, List<string>>
    I ended up placing the items from the value list of the dictionary into two additonal lists a list of distinct values (itemsunique) and then used a foreach loop on a complete list of all the values for all keys in the (allitems):...
    See more | Go to post

    Leave a comment:


  • GTXY20
    started a topic Count unique values in ArrayList C#
    in .NET

    Count unique values in ArrayList C#

    Hi all,

    I have an ArrayList1 of multiple values. Here is an exaple of the a potential ArrayList1:

    a,a,b,,c,a,b,c, c,c,a,b

    Does anyone have any suggestion whereby I could output the count for wach unique item:

    a=4
    b=3
    c=4

    I have done this in python with a defaultdict(int ) and was wondering if there was a quick way in C# to do this other than creating another ArrayList2...
    See more | Go to post

  • GTXY20
    started a topic C# reading CSV file to dictionary question
    in .NET

    C# reading CSV file to dictionary question

    Hi all,

    I currently have a CSV file like so

    1,a
    1,b
    1,c
    2,a
    2,b
    2,b
    2,c
    3,a
    3,a

    I have used an application in Python whereby it reads the file using split with a comma value in a for loop and using the first field as a key in a dictionary and the second field added to a list which is the value for that key. For each line in the file I check to see...
    See more | Go to post

  • GTXY20
    replied to Populate dictionary with text file VB
    in .NET
    Thanks but I am having difficulty assigning the variables to the text file so that if I use split by "," the first variable say a is assigned that value and that will be the key and the next value after the comma is assigned to say variable b and it will be the value for the key - I then need to append to the values where the key is the same when reading the text file and splitting using comma. Something like:

    1,a
    ...
    See more | Go to post

    Leave a comment:


  • GTXY20
    started a topic Populate dictionary with text file VB
    in .NET

    Populate dictionary with text file VB

    Hi All,

    I have been able to create a successful application with Python but I am being asked to create in VB.

    I have a text file with the following data:

    1,a
    1,b
    1,c
    2,a
    2,a
    2,b
    3,a
    3,c

    I need to create a dictionary in VB so that I can then iterate over it so that my key is the first field and my item is the concatenation of unique items...
    See more | Go to post

  • GTXY20
    replied to Windows XP os.chdir() path problem...
    Perfect - thank you.
    See more | Go to post

    Leave a comment:


  • GTXY20
    started a topic Windows XP os.chdir() path problem...

    Windows XP os.chdir() path problem...

    Hi there,

    I have been pulling my hair out with the following error - here is the code:

    Code:
    os.chdir("..\data")
    uhdatafile = open("%s.txt" % self.datafile, 'r')
    which gives me the following error:

    Code:
    WindowsError: [Error 2] The system cannot find the file specified: 'C:\\Documents and Settings\\HHG\\Desktop\\Reportsdata
    can...
    See more | Go to post

  • GTXY20
    replied to Select Unique ID with only a set of values
    Thanks so much - I get it - this seems to work.

    When my queries are finalized I will post.
    See more | Go to post

    Leave a comment:


  • GTXY20
    started a topic Select Unique ID with only a set of values

    Select Unique ID with only a set of values

    Hello all;

    If I have the following data:

    ID Value
    1 A
    1 B
    2 A
    2 B
    2 C
    3 A
    3 B

    How would I go about only selecting the ID's that have only have the combination of values A & B - so my select query woud return:

    ID Value
    1 A
    1 B
    3 A
    3 B...
    See more | Go to post

  • GTXY20
    replied to Creating a nested dictionary...
    Oh I understand, thanks.

    In order to remove these 'bad' entries I am thinkig of putting the follwing in after the dictionary is created to remove:

    Code:
    for key in d:
    	d[key]['v2'].remove('bad')
    See more | Go to post

    Leave a comment:


  • GTXY20
    replied to Creating a nested dictionary...
    actually the code reads as follows but I am still having the same problem:

    Code:
    infile = open('input.txt', 'r')
    records = infile.read()
    infile.close()
    lines = records.split()
    d={}
    for line in lines:
        uh, tf, tp = line.split('%')
        if uh in d:
            f=d[uh]['v1']
            if tf not in f:
                f.append(tf)
            p=d[uh]['v2']
            if tp is
    ...
    See more | Go to post

    Leave a comment:


  • GTXY20
    started a topic Creating a nested dictionary...

    Creating a nested dictionary...

    hello all,

    I have the following text file:

    1,a,good
    1,a,bad
    1,b,good
    1,c,bad

    would like to create a dictionary:

    Code:
    d={1:{'v1':(a,b,c), 'v2':(good)}}
    have been trying:

    Code:
    for line in lines:
        uh, tf, tp = line.split('%')
        if uh in d:
            f=d[uh]['v1']
            if tf not in f:
                f.append(tf)
    ...
    See more | Go to post

  • Associating tuple values to a dictionary key and subsequent values

    Have a little bit of a problem:

    I have the following dictionaries:

    Code:
    d={'1': ['a', 'b', 'c', 'd'], '3': ['a', 'b', 'c', 'd'], '2': ['a', 'b', 'c', 'd'], '4': ['a', 'c']}
    update={'a': 10, 'c': 4, 'b': 5, 'd': 1}
    I use the following to output:


    Code:
    Combqtyoutfile = open('Combqty.txt', 'w')
        Combqtyoutfile.write('Qty\tNumber\tCombination\n')
        from collections
    ...
    See more | Go to post

  • Perfect!

    Thanks so much.
    See more | Go to post

    Leave a comment:


  • Sum values stored in a dictionary as a list of values.

    Hi All,

    I have the following dictionary:

    Code:
    {'1': [10, 5, 4, 1], '3': [10, 5, 4, 1], '2': [10, 5, 4, 1], '4': [10, 4]}
    I need to sum the values for each key and make the dictionary:

    Code:
    {'1': [20], '3': [20], '2': [20], '4': [14]}
    I have tried:


    Code:
    for item in f.values():
                    for items in item:
                        sum
    ...
    See more | Go to post

  • GTXY20
    replied to Create dictionary from another dictionary
    2.4 version works great!

    Thank you.
    See more | Go to post

    Leave a comment:


  • GTXY20
    replied to Create dictionary from another dictionary
    Thanks!

    I am actually using PythonWin 2.5.1.

    Will this cause any problems - I am away from my workstation.
    See more | Go to post

    Leave a comment:


  • GTXY20
    started a topic Create dictionary from another dictionary

    Create dictionary from another dictionary

    Hello;

    I have the following dictionary:

    Code:
    d={1:[a,b,b], 2:[a,a,b,c], 3:[a,b,c], 4:[a,c]}
    I am having trouble removing the duplicate values in each of the keys value list, I need it so that:

    [CODE]d={1:[a,b], 2:[a,b,c], 3:[a,b,c], 4:[a,c]}{/CODE]

    I was thinking of that I would need to import the sets module???
    See more | Go to post

  • GTXY20
    replied to KeyError: 3 problem
    Hi.

    I was able to work out with the following:

    Code:
    def UnitHolderDistributionqty(dictionary):
    from collections import defaultdict
        count=defaultdict(int)
        for item in dictionary.values():
            count[len(item)]+=1
        for k,v in sorted(count.items()):
            fdist=k
            qty=v
            print fdist,qty
    Thanks again.
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...