Question: Did a search on google and here
[an error 3013 thrown when writing a file Adobe AIR](https://stackoverflow.com/questions/8588493/an-error-3013-thrown-when-writing-a-file-adobe-air)
but haven't found a solution yet

Using the Filestream class to simply open and write a file to the ApplicationStorage directory

This works fine on Mac-OSX. But when in Windows I get the following error 

```
Error: Error #3013: File or directory is in use.
    at flash.filesystem::FileStream/open()

```

I've checked permissions both on the actual file and enclosing directory and that doesn't seem to be the problem.

Can anyone suggest a solution or troubleshooting steps?

Answer: 
Non- regex solution using `itertools.groupby`:

```
>>> strs = "this is just is is"
>>> from itertools import groupby
>>> " ".join([k for k,v in groupby(strs.split())])
'this is just is'
>>> strs = "this just so so so nice" 
>>> " ".join([k for k,v in groupby(strs.split())])
'this just so nice'

```
* \b: Matches Word Boundaries
* \w: Any word character
* \1: Replaces the matches with the second word found

```
  import re

  def Remove_Duplicates(Test_string):
      Pattern = r"\b(\w+)(?:\W\1\b)+"
      return re.sub(Pattern, r"\1", Test_string, flags=re.IGNORECASE)

  Test_string1 = "Good bye bye world world"
  Test_string2 = "Ram went went to to his home"
  Test_string3 = "Hello hello world world"
  print(Remove_Duplicates(Test_string1))
  print(Remove_Duplicates(Test_string2))
  print(Remove_Duplicates(Test_string3))

```

Result:

```
    Good bye world
    Ram went to his home
    Hello world

```