Skip to main content
Code Review

Return to Question

Commonmark migration
Source Link

After reading a certain question on the Stack Overflow website, I tried to write a solution to the problem just for fun. I'm, however, left with the nagging feeling there is a beautiful one-liner that can be used instead.

The question's premises:

Create a function that will receive a string. The function will count each vowel in the string, and return a count of all the vowels, whether found or not, each in a tuple pair. Each tuple parir will be stored in a list.

Example:

>>> vowels_finder("This has some vowels")
[('a', 1), ('o', 2), ('u', 0), ('e', 2), ('i', 1)] # tuple pair of each vowel.
>>> 

My attempt:

def vowels_finder(s):
 vowels = {'a':0, 'e':0, 'i':0, 'o':0, 'u':0}
 for el in s:
 if el in {'a', 'e', 'i', 'o', 'u'}:
 vowels[el]+=1
 vowels = [(key, pair) for key, pair in vowels.items()]
 return vowels

My code above is not commented, but I'm confident that its brevity will allow me to pass on this.

Questions:

  • Is there _any way, besides using a python library, that this can be condensed into a one-liner?
  • Would there be a way to not have to convert the vowels key's back into tuple pairs, and just have them be tuples in the beginning. eg: vowels = [('a', 0), ('e', 0), ('i', 0), ('o', 0), ('u', 0)] ?

language: Python 3.4

After reading a certain question on the Stack Overflow website, I tried to write a solution to the problem just for fun. I'm, however, left with the nagging feeling there is a beautiful one-liner that can be used instead.

The question's premises:

Create a function that will receive a string. The function will count each vowel in the string, and return a count of all the vowels, whether found or not, each in a tuple pair. Each tuple parir will be stored in a list.

Example:

>>> vowels_finder("This has some vowels")
[('a', 1), ('o', 2), ('u', 0), ('e', 2), ('i', 1)] # tuple pair of each vowel.
>>> 

My attempt:

def vowels_finder(s):
 vowels = {'a':0, 'e':0, 'i':0, 'o':0, 'u':0}
 for el in s:
 if el in {'a', 'e', 'i', 'o', 'u'}:
 vowels[el]+=1
 vowels = [(key, pair) for key, pair in vowels.items()]
 return vowels

My code above is not commented, but I'm confident that its brevity will allow me to pass on this.

Questions:

  • Is there _any way, besides using a python library, that this can be condensed into a one-liner?
  • Would there be a way to not have to convert the vowels key's back into tuple pairs, and just have them be tuples in the beginning. eg: vowels = [('a', 0), ('e', 0), ('i', 0), ('o', 0), ('u', 0)] ?

language: Python 3.4

After reading a certain question on the Stack Overflow website, I tried to write a solution to the problem just for fun. I'm, however, left with the nagging feeling there is a beautiful one-liner that can be used instead.

The question's premises:

Create a function that will receive a string. The function will count each vowel in the string, and return a count of all the vowels, whether found or not, each in a tuple pair. Each tuple parir will be stored in a list.

Example:

>>> vowels_finder("This has some vowels")
[('a', 1), ('o', 2), ('u', 0), ('e', 2), ('i', 1)] # tuple pair of each vowel.
>>> 

My attempt:

def vowels_finder(s):
 vowels = {'a':0, 'e':0, 'i':0, 'o':0, 'u':0}
 for el in s:
 if el in {'a', 'e', 'i', 'o', 'u'}:
 vowels[el]+=1
 vowels = [(key, pair) for key, pair in vowels.items()]
 return vowels

My code above is not commented, but I'm confident that its brevity will allow me to pass on this.

Questions:

  • Is there _any way, besides using a python library, that this can be condensed into a one-liner?
  • Would there be a way to not have to convert the vowels key's back into tuple pairs, and just have them be tuples in the beginning. eg: vowels = [('a', 0), ('e', 0), ('i', 0), ('o', 0), ('u', 0)] ?

language: Python 3.4

Tweeted twitter.com/StackCodeReview/status/786880111744344064
deleted 39 characters in body
Source Link
Chris
  • 1k
  • 8
  • 21

After reading a certain question on the Stack Overflow website, I tried to write a solution to the problem just for fun. I'm, however, left with the nagging feeling there is a beautiful one-liner that can be used instead.

The question's premises:

Create a function that will receive a string. The function will count each vowel in the string, and return a count of all the vowels, whether found or not, each in a tuple pair. Each tuple parir will be stored in a list.

Example:

>>> vowels_finder("This has some vowels")
[('a', 1), ('o', 2), ('u', 0), ('e', 2), ('i', 1)] # tuple pair of each vowel.
>>> 

My attempt:

def vowels_finder(s):
 vowels = {'a':0, 'e':0, 'i':0, 'o':0, 'u':0}
 for el in s:
 if el in {'a', 'e', 'i', 'o', 'u'}:
 vowels[el]+=1
 vowels = [(key, pair) for key, pair in vowels.items()]
 return vowels

My code above is not commented, but I'm confident that its brevity will allow me to pass on this.

Questions:

  • Is there any way_any way, besides (削除) using a builtin function or method (削除ここまで), Ausing a python library function, that this can be condensed into a one-liner?
  • Would there be a way to not have to convert the vowels key's back into tuple pairs, and just have them be tuples in the beginning. eg: vowels = [('a', 0), ('e', 0), ('i', 0), ('o', 0), ('u', 0)] ?

language: Python 3.4

After reading a certain question on the Stack Overflow website, I tried to write a solution to the problem just for fun. I'm, however, left with the nagging feeling there is a beautiful one-liner that can be used instead.

The question's premises:

Create a function that will receive a string. The function will count each vowel in the string, and return a count of all the vowels, whether found or not, each in a tuple pair. Each tuple parir will be stored in a list.

Example:

>>> vowels_finder("This has some vowels")
[('a', 1), ('o', 2), ('u', 0), ('e', 2), ('i', 1)] # tuple pair of each vowel.
>>> 

My attempt:

def vowels_finder(s):
 vowels = {'a':0, 'e':0, 'i':0, 'o':0, 'u':0}
 for el in s:
 if el in {'a', 'e', 'i', 'o', 'u'}:
 vowels[el]+=1
 vowels = [(key, pair) for key, pair in vowels.items()]
 return vowels

My code above is not commented, but I'm confident that its brevity will allow me to pass on this.

Questions:

  • Is there any way, besides (削除) using a builtin function or method (削除ここまで), A library function that this can be condensed into a one-liner?
  • Would there be a way to not have to convert the vowels key's back into tuple pairs, and just have them be tuples in the beginning. eg: vowels = [('a', 0), ('e', 0), ('i', 0), ('o', 0), ('u', 0)] ?

language: Python 3.4

After reading a certain question on the Stack Overflow website, I tried to write a solution to the problem just for fun. I'm, however, left with the nagging feeling there is a beautiful one-liner that can be used instead.

The question's premises:

Create a function that will receive a string. The function will count each vowel in the string, and return a count of all the vowels, whether found or not, each in a tuple pair. Each tuple parir will be stored in a list.

Example:

>>> vowels_finder("This has some vowels")
[('a', 1), ('o', 2), ('u', 0), ('e', 2), ('i', 1)] # tuple pair of each vowel.
>>> 

My attempt:

def vowels_finder(s):
 vowels = {'a':0, 'e':0, 'i':0, 'o':0, 'u':0}
 for el in s:
 if el in {'a', 'e', 'i', 'o', 'u'}:
 vowels[el]+=1
 vowels = [(key, pair) for key, pair in vowels.items()]
 return vowels

My code above is not commented, but I'm confident that its brevity will allow me to pass on this.

Questions:

  • Is there _any way, besides using a python library, that this can be condensed into a one-liner?
  • Would there be a way to not have to convert the vowels key's back into tuple pairs, and just have them be tuples in the beginning. eg: vowels = [('a', 0), ('e', 0), ('i', 0), ('o', 0), ('u', 0)] ?

language: Python 3.4

added 26 characters in body
Source Link
Chris
  • 1k
  • 8
  • 21

After reading a certain question on the Stack Overflow website, I tried to write a solution to the problem just for fun. I'm, however, left with the nagging feeling there is a beautiful one-liner that can be used instead.

The question's premises:

Create a function that will receive a string. The function will count each vowel in the string, and return a count of all the vowels, whether found or not, each in a tuple pair. Each tuple parir will be stored in a list.

Example:

>>> vowels_finder("This has some vowels")
[('a', 1), ('o', 2), ('u', 0), ('e', 2), ('i', 1)] # tuple pair of each vowel.
>>> 

My attempt:

def vowels_finder(s):
 vowels = {'a':0, 'e':0, 'i':0, 'o':0, 'u':0}
 for el in s:
 if el in {'a', 'e', 'i', 'o', 'u'}:
 vowels[el]+=1
 vowels = [(key, pair) for key, pair in vowels.items()]
 return vowels

My code above is not commented, but I'm confident that its brevity will allow me to pass on this.

Questions:

  • Is there any way, besides using a builtin function or method(削除) using a builtin function or method (削除ここまで), A library function that this can be condensed into a one-liner?
  • Would there be a way to not have to convert the vowels key's back into tuple pairs, and just have them be tuples in the beginning. eg: vowels = [('a', 0), ('e', 0), ('i', 0), ('o', 0), ('u', 0)] ?

language: Python 3.4

After reading a certain question on the Stack Overflow website, I tried to write a solution to the problem just for fun. I'm, however, left with the nagging feeling there is a beautiful one-liner that can be used instead.

The question's premises:

Create a function that will receive a string. The function will count each vowel in the string, and return a count of all the vowels, whether found or not, each in a tuple pair. Each tuple parir will be stored in a list.

Example:

>>> vowels_finder("This has some vowels")
[('a', 1), ('o', 2), ('u', 0), ('e', 2), ('i', 1)] # tuple pair of each vowel.
>>> 

My attempt:

def vowels_finder(s):
 vowels = {'a':0, 'e':0, 'i':0, 'o':0, 'u':0}
 for el in s:
 if el in {'a', 'e', 'i', 'o', 'u'}:
 vowels[el]+=1
 vowels = [(key, pair) for key, pair in vowels.items()]
 return vowels

My code above is not commented, but I'm confident that its brevity will allow me to pass on this.

Questions:

  • Is there any way, besides using a builtin function or method, that this can be condensed into a one-liner?
  • Would there be a way to not have to convert the vowels key's back into tuple pairs, and just have them be tuples in the beginning. eg: vowels = [('a', 0), ('e', 0), ('i', 0), ('o', 0), ('u', 0)] ?

language: Python 3.4

After reading a certain question on the Stack Overflow website, I tried to write a solution to the problem just for fun. I'm, however, left with the nagging feeling there is a beautiful one-liner that can be used instead.

The question's premises:

Create a function that will receive a string. The function will count each vowel in the string, and return a count of all the vowels, whether found or not, each in a tuple pair. Each tuple parir will be stored in a list.

Example:

>>> vowels_finder("This has some vowels")
[('a', 1), ('o', 2), ('u', 0), ('e', 2), ('i', 1)] # tuple pair of each vowel.
>>> 

My attempt:

def vowels_finder(s):
 vowels = {'a':0, 'e':0, 'i':0, 'o':0, 'u':0}
 for el in s:
 if el in {'a', 'e', 'i', 'o', 'u'}:
 vowels[el]+=1
 vowels = [(key, pair) for key, pair in vowels.items()]
 return vowels

My code above is not commented, but I'm confident that its brevity will allow me to pass on this.

Questions:

  • Is there any way, besides (削除) using a builtin function or method (削除ここまで), A library function that this can be condensed into a one-liner?
  • Would there be a way to not have to convert the vowels key's back into tuple pairs, and just have them be tuples in the beginning. eg: vowels = [('a', 0), ('e', 0), ('i', 0), ('o', 0), ('u', 0)] ?

language: Python 3.4

added 2 characters in body
Source Link
Chris
  • 1k
  • 8
  • 21
Loading
Source Link
Chris
  • 1k
  • 8
  • 21
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /