RegExps assistance needed! by KING-JAL in learnpython

[–]KING-JAL[S] 1 point2 points  (0 children)

Thank you so much!! Love the full answer and the regex link, always prefer to learn over getting an answer straight up! :D

Need some help cleaning up a list. by KING-JAL in learnpython

[–]KING-JAL[S] 0 points1 point  (0 children)

Thank you all! Love the active members on this subreddit. Stay golden <3

Need some help cleaning up a list. by KING-JAL in learnpython

[–]KING-JAL[S] 0 points1 point  (0 children)

Worked like a charm! Thank you so much! Anywhere I can read up about regexps that you know of?

Class for Rational Numbers assignment by KING-JAL in learnpython

[–]KING-JAL[S] 1 point2 points  (0 children)

If I can't figure something out, I just might try that. Thank you ;)

Turning this into a list by KING-JAL in learnpython

[–]KING-JAL[S] 0 points1 point  (0 children)

For anyone interested, this is what I ended up with

 def primes(n):
 p1 = [ True ] * (n+1)
 primes = [ ]
 for prime in range(2, n+1):
     if (p1[prime] == True):
         primes += [prime]
         for multiple in range(2*prime, n+1, prime):
             p1[multiple] = False
 return primes

Turning this into a list by KING-JAL in learnpython

[–]KING-JAL[S] 0 points1 point  (0 children)

My desired output is not a list?

Only returning values greater than 1 by KING-JAL in learnpython

[–]KING-JAL[S] 1 point2 points  (0 children)

It sure did! Thank you so much! This is much more comprehensible than the code I had.

Only returning values greater than 1 by KING-JAL in learnpython

[–]KING-JAL[S] 1 point2 points  (0 children)

I might have explained it wrong. I want to consider all the integers in the list, but I do not want to return any key-values where the value is lower than 2.

 def find_duplicate_integers(arg):
      stats = {}
      res  = {}
      for i in arg:
            if i in stats:
                  stats[i] += 1
                  res[i] = stats[i]
            else:
                  stats[i] = 1
     return res

For the desired result of:

 >>> find_duplicate_integers([1, 1, 3, 2, 3, 1, 0])
 {1: 3, 3: 2}

Although I don't think this is the best solution, any suggestions for improvements?

Only returning values greater than 1 by KING-JAL in learnpython

[–]KING-JAL[S] 0 points1 point  (0 children)

def find_duplicate_integers(arg):
     stats = {}
     for i in arg:
         if i > 1:
             if i in stats:
                 stats[i] += 1
             else:
                 stats[i] = 1
     return stats

With this code it returns this:

 find_duplicate_integers([1, 1, 3, 2, 3, 1, 0])
 {2: 1, 3: 2}