Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

GH Python - very basic query

$
0
0

Hello everyone,
I am trying to learn Python and use it in GH.
This is my very first attempt, so I beg your pardon beforehand.
Thanks so much

I am trying to check a list of strings, if they contain “RC”, I leave it as it is, if not, I want to replace " " with “” (as in remove spaces) and replace “.0” with “” (as in remove “.0” from the string). The desired output will be the updated list of strings.
The input is set to List access.

import rhinoscriptsyntax as rs
# Initialize an empty list to store the output
output_list = [ ]

 # Iterate through each item in the input list
for item in input_list:
    # Check if the item contains "RC"
    if "RC" in item:
        # If it does, add it to the output list as is
        output_list.append(item)
    else:
        # If not, remove spaces and ".0" and add to the output list
        cleaned_item = item.replace(" ", "").replace(".0", "")
        output_list.append(cleaned_item)

# Output the updated list of strings
output = output_list

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles