I want to generate a list of field names to use a input for arcpy.TransposeFields_management.
The list of fields for the transpose needs to be in this format:
in_field="VALUE1 VALUE1;VALUE2 VALUE; VALUE3 VALUE3"
but the closest I can get is:
in_field="VALUE1; VALUE1;VALUE2; VALUE; VALUE3; VALUE3"
using code below.
How can I prepare a list of field names for transpose tool?
field_names = []
fields = arcpy.ListFields(TabulateArea)
for field in fields:
field_names.append(field.name)
del field_names[0:2] #Don't need first two fields
a = field_names
b = []
for i in a:
b.extend([i,I]) #duplicating field names
delimited_list = ' ;'.join(b) # adding semi-colon and space
print(delimited_list)
VALUE_2 ;VALUE_2 ;VALUE_8 ;VALUE_8 ;VALUE_9 ;VALUE_9 ;VALUE_10 ;VALUE_10 ;VALUE_11 ;VALUE_11 ;VALUE_17 ;VALUE_17
like this?
a = ['a', 'b', 'c', 'd', 'e'] # -- list fields
";".join([f'{i} {i}' for i in a])
'a a;b b;c c;d d;e e'