Search Results

Search found 2 results on 1 pages for 'user1730056'.

Page 1/1 | 1 

  • Display values and how many times they occured using a Dictionary

    - by user1730056
    I've been told to By using a dictionary (or your solution to Part 4), write a method at_least(a, n) that takes a list, a, and an integer, n, as arguments and returns a list containing only the elements of a that occur at least n times. For complete marks, the list should contain the elements in order of their first occurrence in a. I was able to figure this without using a dictionary, with def at_least2(a, n): return [x for x in a if a.count(x) is n] I was wondering how I can write this using a dictionary? The input is: a = [-6, 8, 7, 3, 2, -9, 1, -3, 2, -4, 4, -8, 7, 8, 2, -2, -7, 0, 1, -9, -3, -7, -3, -5, 6, -3, 6, -3, -10, -8] def at_least(a, 2): and the output: [8, 7, 2, -9, 1, -3, 2, -8, 7, 8, 2, -7, 1, -9, -3, -7, -3, 6, -3, 6, -3, -8] Edit: I don't understand how a dictionary is being used, yet the output isn't in dictionary form? My understanding is that dictionaries have values for each object. I'm not sure if I'm using the right terms.

    Read the article

  • Simple Java math operations

    - by user1730056
    I'm making a BMI calculator that doesn't seem to be working. The math operations work if i just do something like w/h, but once i had the brackets, it returns an error. If i change the variables w and h and use a constant number, the operation works. Another problem is that although i'm making result a double, it seems to be rounding to the nearest int. Could someone tell me what I'm doing wrong here? public class ass10 { public static void main(String[] args) { bmi(223,100); } public static bmi(int w, int h){ double result; result = (w/(h*h))*703 System.out.println(result) } }

    Read the article

1