اذهب إلى المحتوى
  • 0

تحويل جملة إلى snake_case في بايثون

Mohamed Farahat

السؤال

مرحبا,

I've been stuck on this problem for a while. Could someone help me, please? Thank you in advance

def convert_to_snake_case(pascal_or_camel_cased_string):

    snake_cased_char_list = []
    for char in pascal_or_camel_cased_string:
        if char.isupper():
            converted_character = '_' + char.lower()
            snake_cased_char_list.append(converted_character)
        else:
            snake_cased_char_list.append(char)
    snake_cased_string = ''.join(snake_cased_char_list)
    clean_snake_cased_string = snake_cased_string.strip('_')

    return clean_snake_cased_string

def main():
    pass

Inside the main() function, replace pass with a convert_to_snake_case() call. Pass the string 'aLongAndComplexString' as input to the function and print out the output using the print() function.

تم التعديل في بواسطة Mohamed Farahat
رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

الحل الخاص بك صحيح و إنما فقط ينقصك أن تستعمل الدالة و إعطائها الجملة aLongAndComplexString كمدخلات و تطبع النتيجة و للقيام بذلك يمكنك التعديل على main، و يمكنك القيام بذلك لوحدك عليك المحاولة أكثر، ما تحتاج القيام به هو تعريف مثلا متغير داخل main هكذا

input_string = 'aLongAndComplexString'

بعدها استدعيه داخل الدالة ليتم تطبيق التغييرات عليه و إطبع النتيجة، و يمكنك أن تطلع أكثر على كيفية عمل الدوال من هنا:

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0

def main():

    input_string = 'aLongAndComplexString'

    print(input_string)

Sorry, your code does not pass. Keep trying.

You should call convert_to_snake_case() inside the main() function and pass 'aLongAndComplexString' as input to the function.

Just got it thank you for your help

def main():

    convert_to_snake_case()

    my_function("Input String")

    print(convert_to_snake_case('aLongAndComplexString'))

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...