Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Apart from the awesome answer @Phrancis just gave just gave, I'll just address the part of the question where it asks for a one-liner. You can have something like this, if that's really necessary:

def find_vowels_1(data):
 return [(k, v) for k, v in {v: data.lower().count(v) for v in 'aeiou'}.items()]
print(find_vowels_1('dexter'))

Which will print:

[('o', 0), ('e', 2), ('i', 0), ('a', 0), ('u', 0)]

Bear with the fact that I don't recommend this solution as it won't bring anything good. I'd just follow everything it was stated in the above answer.


As others mentioned, is redundant to have a dict which will then be converted to a list. So you can build a list from the start. More, you can also make another function argument vowels in which you can pass the vowels specific to a different region:

def find_vowels_1(data, vowels='aeiou'):
 # return the number of occurrences of each vowel in a string
 return [(v, data.count(v)) for v in vowels]
print(find_vowels_1('dexter'))

Apart from the awesome answer @Phrancis just gave, I'll just address the part of the question where it asks for a one-liner. You can have something like this, if that's really necessary:

def find_vowels_1(data):
 return [(k, v) for k, v in {v: data.lower().count(v) for v in 'aeiou'}.items()]
print(find_vowels_1('dexter'))

Which will print:

[('o', 0), ('e', 2), ('i', 0), ('a', 0), ('u', 0)]

Bear with the fact that I don't recommend this solution as it won't bring anything good. I'd just follow everything it was stated in the above answer.


As others mentioned, is redundant to have a dict which will then be converted to a list. So you can build a list from the start. More, you can also make another function argument vowels in which you can pass the vowels specific to a different region:

def find_vowels_1(data, vowels='aeiou'):
 # return the number of occurrences of each vowel in a string
 return [(v, data.count(v)) for v in vowels]
print(find_vowels_1('dexter'))

Apart from the awesome answer @Phrancis just gave, I'll just address the part of the question where it asks for a one-liner. You can have something like this, if that's really necessary:

def find_vowels_1(data):
 return [(k, v) for k, v in {v: data.lower().count(v) for v in 'aeiou'}.items()]
print(find_vowels_1('dexter'))

Which will print:

[('o', 0), ('e', 2), ('i', 0), ('a', 0), ('u', 0)]

Bear with the fact that I don't recommend this solution as it won't bring anything good. I'd just follow everything it was stated in the above answer.


As others mentioned, is redundant to have a dict which will then be converted to a list. So you can build a list from the start. More, you can also make another function argument vowels in which you can pass the vowels specific to a different region:

def find_vowels_1(data, vowels='aeiou'):
 # return the number of occurrences of each vowel in a string
 return [(v, data.count(v)) for v in vowels]
print(find_vowels_1('dexter'))
added 304 characters in body
Source Link
Grajdeanu Alex
  • 9.3k
  • 4
  • 32
  • 71

Apart from the awesome answer @Phrancis just gave, I'll just address the part of the question where it asks for a one-liner. You can have something like this, if that's really necessary:

def find_vowels_1(data):
 return [(k, v) for k, v in {v: data.lower().count(v) for v in 'aeiou'}.items()]
print(find_vowels_1('dexter'))

Which will print:

[('o', 0), ('e', 2), ('i', 0), ('a', 0), ('u', 0)]

Bear with the fact that I don't recommend this solution as it won't bring anything good. I'd just follow everything it was stated in the above answer.


There are disadvantages when it comesAs others mentioned, is redundant to one-linershave a dict which will then be converted to a list. For exampleSo you can build a list from the start. More, you can also make another function argument vowels in which you can pass the vowels specific to a different region:

  • you can't treat the special y case
  • it's harder to read than the above mentioned solutions
  • and so on
def find_vowels_1(data, vowels='aeiou'):
 # return the number of occurrences of each vowel in a string
 return [(v, data.count(v)) for v in vowels]
print(find_vowels_1('dexter'))

Apart from the awesome answer @Phrancis just gave, I'll just address the part of the question where it asks for a one-liner. You can have something like this, if that's really necessary:

def find_vowels_1(data):
 return [(k, v) for k, v in {v: data.lower().count(v) for v in 'aeiou'}.items()]
print(find_vowels_1('dexter'))

Which will print:

[('o', 0), ('e', 2), ('i', 0), ('a', 0), ('u', 0)]

Bear with the fact that I don't recommend this solution as it won't bring anything good. I'd just follow everything it was stated in the above answer.

There are disadvantages when it comes to one-liners. For example:

  • you can't treat the special y case
  • it's harder to read than the above mentioned solutions
  • and so on

Apart from the awesome answer @Phrancis just gave, I'll just address the part of the question where it asks for a one-liner. You can have something like this, if that's really necessary:

def find_vowels_1(data):
 return [(k, v) for k, v in {v: data.lower().count(v) for v in 'aeiou'}.items()]
print(find_vowels_1('dexter'))

Which will print:

[('o', 0), ('e', 2), ('i', 0), ('a', 0), ('u', 0)]

Bear with the fact that I don't recommend this solution as it won't bring anything good. I'd just follow everything it was stated in the above answer.


As others mentioned, is redundant to have a dict which will then be converted to a list. So you can build a list from the start. More, you can also make another function argument vowels in which you can pass the vowels specific to a different region:

def find_vowels_1(data, vowels='aeiou'):
 # return the number of occurrences of each vowel in a string
 return [(v, data.count(v)) for v in vowels]
print(find_vowels_1('dexter'))
added 2 characters in body
Source Link
Grajdeanu Alex
  • 9.3k
  • 4
  • 32
  • 71

Apart from the awesome answer @Phrancis just gave, I'll just address the part of the question where it asks for a one-liner. You can have something like this, if that's really necessary:

def find_vowels_1(data):
 return [(k, v) for k, v in {v: data.lower().count(v) for v in 'aeiou'}.items()]
print(find_vowels_1('dexter'))

Which will print:

[('o', 0), ('e', 2), ('i', 0), ('a', 0), ('u', 0)]

Bear with the fact that I don't recommend this solution as it won't bring anything good. I'd just follow everything it was stated in the above answer.

There are disadvantages when it comes to one-liners. For example:

  • you can't treat the special y case
  • itit's harder to read than the above mentioned solutions
  • and so on

Apart from the awesome answer @Phrancis just gave, I'll just address the part of the question where it asks for a one-liner. You can have something like this, if that's really necessary:

def find_vowels_1(data):
 return [(k, v) for k, v in {v: data.lower().count(v) for v in 'aeiou'}.items()]
print(find_vowels_1('dexter'))

Which will print:

[('o', 0), ('e', 2), ('i', 0), ('a', 0), ('u', 0)]

Bear with the fact that I don't recommend this solution as it won't bring anything good. I'd just follow everything it was stated in the above answer.

There are disadvantages when it comes to one-liners. For example:

  • you can't treat the special y case
  • it harder to read than the above mentioned solutions
  • and so on

Apart from the awesome answer @Phrancis just gave, I'll just address the part of the question where it asks for a one-liner. You can have something like this, if that's really necessary:

def find_vowels_1(data):
 return [(k, v) for k, v in {v: data.lower().count(v) for v in 'aeiou'}.items()]
print(find_vowels_1('dexter'))

Which will print:

[('o', 0), ('e', 2), ('i', 0), ('a', 0), ('u', 0)]

Bear with the fact that I don't recommend this solution as it won't bring anything good. I'd just follow everything it was stated in the above answer.

There are disadvantages when it comes to one-liners. For example:

  • you can't treat the special y case
  • it's harder to read than the above mentioned solutions
  • and so on
added 181 characters in body
Source Link
Grajdeanu Alex
  • 9.3k
  • 4
  • 32
  • 71
Loading
Source Link
Grajdeanu Alex
  • 9.3k
  • 4
  • 32
  • 71
Loading
lang-py

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