-1

Say I have a function

parameter 1 - a list of strings, each string element is a friend's email parameter 2 - a string, a friend's email you'd should to add to the list or if empty, do not add (just clean the list and remove repeats)

def email_list(previous_emails, new_email):

and this list of emails is used ['media@gmail.com', 'carpool@gmail.com', 'marcopolo@gmail.com', 'MEDIA@gmail.com'] but it just prints this list again instead of just the first 3 emails.

I tried to use different methods i found on here but nothing is really getting rid of the duplicates, it just keeps printing the orginal list.

  • There are no duplicate strings in the list you have shown. Upper-case and lower-case versions are different strings. – mkrieger1 Apr 14 '23 at 01:40
  • You need to [lower the case of the characters](https://docs.python.org/3/library/stdtypes.html#str.lower) – Rojo Apr 14 '23 at 01:52
  • @Rojo `.casefold` might be better than `.lower`, although, I don't actually know what would be appropriate for emails. In any case, `.lower` is probably find for this exercise. – juanpa.arrivillaga Apr 14 '23 at 02:03
  • @juanpa.arrivillaga `casefold` would too aggressive for an email since 'ß' is not equivalent to "ss" in a URL (I highly doubt ß would ever appear in an email/URL, but still). – Rojo Apr 14 '23 at 02:16
  • @Rojo yes, although, I do know that, for example, `.` are ignored in email addresses, but I think this is just a practice exercise – juanpa.arrivillaga Apr 14 '23 at 02:16

1 Answers1

0

You can do the following:

def email_list(previous_emails, new_email):
  previous_emails.extend(new_email)
  return list(set(previous_emails))
email_list(['a', 'b'], ['c', 'b'])
TanjiroLL
  • 1,354
  • 1
  • 5
  • 5