title: How to check that a comma-separated string in Python contains only single commas?
body: <p>I'm trying to check the validity of comma-separated strings in python. That is, it's possible that the strings contain mistakes whereby there are more than one comma used.</p>
  <p>Here is a valid string:</p>
  <pre><code>foo = &quot;a, b, c, d, e&quot;
  </code></pre>
  <p>This is a valid string as it is comma-delimited; only one comma, not several or spaces only.</p>
  <p>Here is an invalid string:</p>
  <pre><code>invalid = &quot;a,, b, c,,,,d, e,,; f, g&quot;
  </code></pre>
  <p>The invalid string is invalid because (1) it uses more than one comma and (2) it also uses a semicolon <code>;</code>.</p>
  <p>What would be the most effective way to check that the strings are valid?</p>
  <p>My first attempt was to try something like:</p>
  <pre><code>def check_valid_string(input_string):
      if &quot;,,&quot; in input_string or &quot;;&quot; in input_string:
          return &quot;Not valid&quot; ## or False
      else:
          return &quot;Valid&quot; ## or True
  </code></pre>
  <p>however, it's not clear that this would catch all possible invalid strings. It's also not clear to me that this approach is the most computationally efficient (i.e. quick).</p>