Skip to content

Instantly share code, notes, and snippets.

@summerofgeorge
Created March 19, 2025 01:33
Force to list Python in Excel
def force_to_list(value):
if isinstance(value, pd.DataFrame):
return value.values.flatten().tolist()
elif isinstance(value, str):
return [value] # Wrap single string in a list
elif hasattr(value, '__iter__') and not isinstance(value, str):
return list(value) # Handle other iterable types
else:
return [value] # Wrap scalars in a list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment