You can use Select (Analysis) to perform this operation. This method has the added benefit of preserving your attributes. There are two main steps:
- Use a generator to list all of the unique city codes
- Loop through unique cities codes and add the code to the Select SQL expression
import arcpy, os
# Define the output workspace
outws = r'C:\temp\out'
# Set the input shapefile
shp = r'C:\temp\test.shp'
# Get a list of unique city codes using a generator
cities = set(row[0] for row in arcpy.da.SearchCursor(shp, "city"))
# Select unique cities and export to new shapefiles
for c in cities:
out_fc = os.path.join(outws, c) # Define the output name
where_clause = '"city" = \'%s\'' % c # Select based on city name
arcpy.Select_analysis(shp, out_fc, where_clause) # Perform the Select